Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

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

As a general thing lines that are very long, especially if there is important stuff at the end, and even worse of the structure is convoluted, compared with short lines are hard to understand. Keep your lines short, or at least wrap them sensibly. For example:

return $self->{'dbh'}->selectrow_array("SELECT COUNT(*) FROM $Bod: +:Variables::M_Table WHERE $Bod::Variables::C_Table_id$Bod::Variables: +:C_Table = ?, $Bod::Variables::B_Table_id$Bod::Variables::B_Table = ? + AND Permission_idPermission = ? AND date > NOW() - INTERVAL 2 SECOND +", undef, $contact, $business, $permission);

is easier to maintain written:

return $self->{'dbh'}->selectrow_array( "SELECT COUNT(*) FROM $Bod::Variables::M_Table WHERE $Bod::Variables::C_Table_id$Bod::Variables::C_Table += ?, $Bod::Variables::B_Table_id$Bod::Variables::B_Tabl +e = ? AND Permission_idPermission = ? AND date > NOW() - INTERVAL 2 SECOND", undef, $contact, $business, $permission );

Consider using spaces instead of tabs for indentation.

Consider having new return an instance of Bod::CRM with its error field set, or throw an exception, for a DB connection failure.

Consider removing warnings in lower level code. Low level code may not have enough context to be really helpful and low level warnings can end up generating a noisy log. Calling code can emit warnings if appropriate and can generally provide a better semantic context.

Consider using exceptions for handling all errors so that calling code can chunk error handling into blocks of related code rather than having to deal with handling errors on all function calls. That extends quite well to having DBI code throw exceptions rather than having fine grain error checking at a low level (see RaiseWarn and RaiseError in DBI).

Consider passing named parameters to find and add. That way your existing hash ref gets passed in as a hash with no other change, but a simple find doesn't need to have a hash ref spun up. That makes it easier to write the code and easier to read and check:

my %fields = ( firstname => 'John', lastname => 'Smith', pri_email => 'john.smith@example.com', ); $crm->add(%fields); $crm->add(firstname => 'John', lastname => 'Smith', pri_email => ' +john@xxxx.com'); my @contacts = $crm->find(firstname => 'John');
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

In reply to Re: [RFC] Review of module code and POD by GrandFather
in thread [RFC] Review of module code and POD by Bod

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.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-26 03:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found