Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hello, I'd like some advice on good perl style. I wrote a module for CGI error handling that I like the functionality of, but I think the interface needs some refinement.

The issue is this: The module needs to have some intelligent defaults, but these can be overridden by a module that calls it. For a given module that calls my error module (let's say, it has it's own defaults, which can in turn be overridden a per-script basis.

Right now I have a routine in which basically collects the values from the calling script, adds in defaults for abstent variables and returns

It seems like there should be a slicker way than writing this wrapper routine to call the module though. Perhaps there is an answer somewhere in OO I can use?

I'll create some sample peusdo-code here in case someone wants to rework it for an example.

package sub err { my %args = ( title =>'Really Bad Error', msg => undef, @_ ); # do something with %args here. } ########### package; use; sub err { my %args = ( title =>'My new default title for', msg => 'MyModules generic error message', @_ ); return Err::err(%args); } ################## ### my script.cgi package MyModule; do_the_right_thing() || err(title=>'Oops',msg=>'something went wrong') +;

I hope that made sense. Thanks for any suggestions.


In reply to Handling cascading defaults by markjugg

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (5)
    As of 2020-12-04 14:50 GMT
    Find Nodes?
      Voting Booth?
      How often do you use taint mode?

      Results (60 votes). Check out past polls.