Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

When something goes from working to not working and you think you didn't change anything significant, you usually just made one dumb little mistake. If you want debugging to be easy, put lots of feedback in your code to report when it's used incorrectly (and write tests for it). Try this for starters-

use Carp; sub get_zip { my $self = shift; my $city = uc(+shift) || croak "No city given"; my $state = uc(+shift) || croak "No state given"; my $zip = $self->single({ city_name => $city, state_abbr => $state }, { columns => [qw/zip_code/] } ); if ( $zip ) { return $zip->zip_code; } else { carp "No ZIP found for city_name:$city and state_abbr:$state"; } return undef; }

I'm a fan of the die early, die often edict (hence the croaks) but you can tone it down or adapt. The main idea is just to never assume that your code will be called as designed and account for that. See also Params::Validate.


In reply to Re: MVC Catalyst Architecture - City, State Zip locator by Your Mother
in thread MVC Catalyst Architecture - City, State Zip locator by ChristinaH

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.