I am trying to extract information from within a stream of information coming from a web server to a web browser. To do this I have been using the HTTP::Proxy (http://search.cpan.org/~book/HTTP-Proxy-0.24/lib/HTTP/Proxy.pm). I have been successful at installing the proxy and getting the browser to access the server using the proxy. I have even been successful at getting the proxy to store the data in a MySQL database.
My problem is when I try to set up the DBI interface in the init subroutine and use it in the filter subroutine. I want to do this way as to not incur the cost of setting up the DBI connection each time the filter is called. This will happen at least 1 time per second.
Here is the code:
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;
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.