and an accessor like so:sub _setup_dbh { my $self = shift; $self->{'_dbh'} = DBI->connect( $dsn, $username, $password ); return $self->{'_dbh'}; }
Which means some client code can do the following:sub get_dbh { my $self = shift; return $self->{'_dbh'}; }
That's all fine... HOWEVER.... I want to throw another method into that $dbh object; something like:$dbh = $foo->get_dbh; $dbh->prepare( "blah blah whatever" )
How do I get that 'dbq' method into that _dbh object? So the client code could do:sub dbq { my $self = shift; my $sql = shift; my ( $sth ); $sth = $self->{'_dbh'}->prepare( $sql ); $sth->execute; return $sth; }
I of course still want to keep all the other methods that the _dbh object has. Also, the example is just for illustration purposes... basically, I have a class "foo" that instantiates an object of some other completely external class, "bar"; but it's imperative that I stuff that object "bar" with my own method that is defined within my class "foo". Your kindly assistance is most appreciated!$dbh = $foo->get_dbh; $dbh->dbq( "blah blah whatever" );
In reply to object method question by Zarathustra
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |