Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm tring to get a handle on a bunch of Perlish things, i.e. OO, modules, Class::DBI, namespaces, CPAN, ...

Well Perl OK.

When dealing with Class::DBI I find I do the same things over and over. So I overide the base class methods and do it my way. For example I want Class::DBI to do the following:

$id = $obj->create({id =>999, number_of_days_on_the_job=>3, number_of_people_shot=>12}); $error_string = $id unless $id == 999; # overide default die behavour and # return the error message if it fails constraints # for HTML::Template to 'associate' with $obj->param('number_of_people_shot'); print "The known fields are ".$obj->param()."\n"; %errors = $obj->set( number_of_days_on_the_job => 4, number_of_people_shot => 27); # or more to the point %errors = $obj->set( $CGI->Vars ); # i.e. don't die! also # don't update any of the values if there are any errors. # and collect errors in hash for each error. print $error{number_of_people_shot} if $error{number_of_people_shot} exists; ($dead, $x, $days) = $obj->get( number_of_days_on_the_job, x, number_of_people_shot); # NOTE x is not in the table print $x # prints some nonsense about that it - 'cant get nothing'
What I'm asking is, well ... Do I get it? Or is this increadably dumb? Should I submit it to CPAN and wait for the royalty checks and parades? or is it just tooooo trivial? Its really quite simple - but it seems usefull.

Replies are listed 'Best First'.
Re: Trivial CPAN module?
by friedo (Prior) on Dec 11, 2005 at 00:15 UTC
    Before uploading to CPAN, I would reccomend posting an RFC in the "Meditations" section. That way you can get some useful feedback before you release.
Re: Trivial CPAN module?
by Perl Mouse (Chaplain) on Dec 10, 2005 at 23:55 UTC
    If you think it's useful, upload in on CPAN. If other people think so as well, they'll be grateful. If they don't, well, then the module is just occupying a small fragment of a disk. No big deal.
    Perl --((8:>*
Re: Trivial CPAN module?
by perrin (Chancellor) on Dec 11, 2005 at 17:49 UTC
    Have you seen Class::DBI::FromCGI? This seems to have some overlap. Also, why are you changing exceptions into return codes that have to be checked? Exceptions are generally considered to be a better way to do things.
      Yeah thanks, I didn't know about FromCGI. Just glancing at it it seems to do many of the same things.

      I'm courious though, I'm not sure I follow you when you say

      "why are you changing exceptions into return codes that have to be checked"

      If I do understand, its because I don't want it to die, and I want to collect all of the possible errors and there causes. Dosen't FromCGI do the same?

        The idea with exceptions is that you catch them only if you want to handle them and continue in some way. Usually this means it's your client code that would be catching them, not a base class, although it's possible that doing this in a base class could make sense in certain situations.

        Converting them to error codes is a red flag because error codes have problems that exceptions were supposed to address -- namely that if you forget to check one, your program will continue as if everything is okay.