in reply to Re: Best practices for passing $dbh to subroutines
in thread Best practices for passing $dbh to subroutines

Of course, every method call gets implicitly the object as its first parameter. In this case the database handle is the explicit first parameter.

Same same but different.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics
  • Comment on Re^2: Best practices for passing $dbh to subroutines

Replies are listed 'Best First'.
Re^3: Best practices for passing $dbh to subroutines
by choroba (Cardinal) on Jan 27, 2014 at 09:20 UTC
    I usually store the handle somewhere deeper in the object, with prepared selects or inserts around. So, the methods look like:
    sub add_numbers { my ($self, @params) = @_; $self->{insert_num}->execute(@params); } sub vacuum { my $self = shift; $self->{db}->do('vacuum'); }
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ