in reply to Re^2: object method question
in thread object method question
If you really want to do this, and you are smart about it (eg. your method only calls the publicly documented DBI methods on itself) then you simply need to define a new method in the right package space.
For example, if you wanted to have a method that returned the most recent database error in all uppercase (to make sure it is heard loud and clear!), you could include this fragment in your code somewhere:
What the surrounding curly braces do is define a scopeso that the package pragma only applies within that scope. The sub/method err_loud thus becomes DBI::err_loud and will be found when perl tries to resolve the method call $dbh->err_loud(){ package DBI; sub err_loud { my $self = shift; return uc( $self->err() ); } }
Perl trusts you not to shoot yourself in the foot, so you want to be really sure that this is what you want to do. As other posters have said, it would be more conventional to make a subclass.
|
|---|