I had serious problem with some of my own code the other day.
I am using a DBIx::Class relative to access a database for writing.
So I am building a record structure (not a database record) containing some objects referencing to other objects representing database records and I only want to serialize this new record to the database if everything is ok... so I check 3 points in my shallow record to see if these (foreign) keys are present.} elsif ($record{'operator'} && $record{'country'} && $record{'currency'}) {
And this just did not work, I was puzzled, I dumped the $record and the data was there. I printed out the three values and I could only see the two, even more puzzled...
The solution was quite obvious when discovered, but until that it was quite hard to figure out (as it often is).
Well the problem was that referring to the objects in that particular way would result in a stringification so the names where returned, for the currency no name was however specified resulting in an empty string, meaning false, so the better to write the above is:} elsif ($record{'operator'}->id && $record{'country'}->id && $record{'currency'}->id) {
Lessons learned:
1. watch out in the case of stringification if the value used for the stringification is not default at least something or is defined not to be able to be empty
2. when asserting, assert on something you know will be set like the key or id