Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Passing a database connection

by dragonchild (Archbishop)
on Nov 22, 2005 at 21:33 UTC ( #510916=note: print w/replies, xml ) Need Help??


in reply to Passing a database connection

You retyped, you didn't cut'n'paste. You're actually calling it as Main->new( $dbh ), not Main::new( $dbh ). Using Main->new() calls it as a method and passes the receiver (in this case, 'Main') in as the first parameter.

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^2: Passing a database connection
by aufflick (Deacon) on Nov 23, 2005 at 00:30 UTC
    If the rest of your code uses OO mechanisms, you might want to recode new() so it will work as a class method rather than calling it as a non OO sub (ie. Main::new). The example below also checks that the passed in var is a valid DBI object. If you had done that in your code, you would have received an error as soon as you called the new method.
    package Main; use strict; my $dbh; sub new { my $class = shift; my $dbh = shift; UNIVERSAL::isa($dbh, 'DBI') or die "Main->new() was invoked without a valid DBI object"; }
Re^2: Passing a database connection
by Spidy (Chaplain) on Nov 22, 2005 at 21:36 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://510916]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2018-07-20 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (438 votes). Check out past polls.

    Notices?