Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I know the init is being called to initialize the object and I know the filter is being called when a message is passed through the proxy. I can tell this by the DB entries that are made after running the code. The problem is that the query objects are not being stored in the hash of the filter object or they are not being retrieved properly. So, how do I store an object within an object and retrieve it. Thanks for any help you can give PS The way I attacked this problem was to store the reference to the query object in the filter object's hash in the init and then to retrieve that reference in the filter. Not to sure how to cast a reference back to an object. This may be the problem.package testfilter; use strict; use warnings; use DBI; use base qw( HTTP::Proxy::HeaderFilter ); sub init {my ($self) = @_; # Connect to the database.and store the reference in the hash my $dbh = DBI->connect("dbi:mysql:woo",'swoo','password', {'RaiseE +rror' => 1}); my $inth = $dbh->prepare( q{INSERT INTO foo (id, name) VALUES (?, +?)}); $inth->execute("1","jim"); $self->{INSERT} = \$inth; } sub filter { my ( $self, $headers, $message ) = @_; my $inth = $self->{INSERT}; $inth->execute("2","tom"); my $dbha = DBI->connect("dbi:mysql:woo",'woo','password', {'RaiseE +rror' => 1}); my $intha = $dbha->prepare( q{INSERT INTO foobar (id, name) VALUES + (?, ?)}); $intha->execute("1","$self->{INSERT}"); } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Object in an object
by ikegami (Patriarch) on Oct 03, 2009 at 03:31 UTC | |
by Anonymous Monk on Oct 04, 2009 at 17:48 UTC | |
by ikegami (Patriarch) on Oct 04, 2009 at 23:12 UTC | |
by ikegami (Patriarch) on Oct 04, 2009 at 23:09 UTC | |
|
Re: Object in an object
by CountZero (Bishop) on Oct 03, 2009 at 07:04 UTC |