Tricks

Beatnik on 2003-12-07T17:41:09

2 small tweaks I applied to my code in the last months...

  • Module::default, to be used like $object = OtherModule->get(...) || Module::default;. Basically I want OtherModule::get to return an instance of Module (from an unidentified source). If, for some reason, it can't, I want to use the default values. The reason why I'm not stuffing default values in the constructor at this point is basically because I don't always want the default values.
  • Foo::tohash, where Module is a basic getter/setter class. I use it to pass around values. In the database layer I have a DBFoo, which inherits almost everything from DBModule. I only change the DB fields in DBFoo so it will use the hash for storing the record in the DB (after doing proper checking ofcourse.