Why not adopt me?
NAME
POE::Component::WWW::Search::Mininova - non-blocking POE wrapper for WWW::Search::Mininova
SYNOPSIS
use strict;
use warnings;
use POE qw(Component::WWW::Search::Mininova);
my $mini_poco
= POE::Component::WWW::Search::Mininova->spawn( alias => 'mini' );
POE::Session->create(
package_states => [
'main' => [ qw(_start mini) ],
]
);
$poe_kernel->run;
sub _start {
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
$mini->search( {
term => 'test',
category => 'Music',
sort => 'Seeds',
ua => 'Torrent Searcher',
timeout => 180,
event => 'mini',
_arbitrary_value => 'whatever',
} );
$kernel->post(
'mini' => 'search' => {
term => 'test',
event => 'mini',
_arbitrary_value => 'whatever',
}
);
undef;
}
sub mini {
my ( $kernel, $results ) = @_[ KERNEL, ARG0 ];
if ( $results->{error} ) {
print "ZOMG! An error: $results->{error}\n";
}
else {
use Data::Dumper;
print Dumper( $results->{out} );
}
print $results->{_arbitrary_value}, "\n";
$kernel->post( 'mini' => 'shutdown' );
undef;
}
DESCRIPTION
The module is a simple non-blocking POE wrapper for WWW::Search::Mininova
CONSTRUCTOR
my $mini = POE::Component::WWW::Search::Mininova->spawn;
Takes a three optional arguments.
alias
POE::Component::WWW::Search::Mininova->spawn( alias => 'mini' );
Specifies a POE Kernel alias for the component.
options
POE::Component::WWW::Search::Mininova->spawn(
options => {
trace => 1,
default => 1,
},
);
A hashref of POE Session options to pass to the component's session.
debug
POE::Component::WWW::Search::Mininova->spawn( debug => 1 );
Turns on printing of a few debug messages. Note: you must set this option to a true value if you wish to print out debug messages from WWW::Search::Mininova object.
METHODS
These are the object-oriented methods of the components.
search
$mini_poco->search(
{
term => 'foos',
event => 'mini',
}
);
Takes hashref of arguments. See search
method below for description.
session_id
my $mini_id = $mini_poco->session_id;
Takes no arguments. Returns POE Session ID of the component.
shutdown
$mini_poco->shutdown;
Takes no arguments. Terminates the component.
ACCEPTED EVENTS
search
$poe_kernel->post( 'mini' => 'search' => {
term => 'foos',
event => 'mini',
}
);
$poe_kernel->post( 'mini' => 'search' => {
term => 'foos',
event => 'mini',
timeout => 10,
_arbitrary_value => 'whatever',
_moar_shtuf => 'something else',
}
);
Instructs the component to make a search. Requires a hashref as an argument. Hashref keys are as follows:
term
{ term => 'foos' }
Mandatory. The term to search mininova.org for. The value you would pass as an argument to the search()
method of WWW::Search::Minonova object.
event
{ event => 'mini' }
Mandatory. The event name to send the response to.
category
{ category => 'Music' }
Optional. Tells the component on which category to perform the search on. See WWW::Search::Minonova object's category
method for more information.
sort
{ sort => 'Seeds' }
Optional. Tells the component on which column the most relevant results should be based on. See WWW::Search::Minonova object's sort()
method for more information.
timeout
{ timeout => 50 }
Optional. Search request timeout. See WWW::Search::Minonova object's timeout()
method for details.
ua
{ ua => 'Torrent Searcher' }
Optional. User-Agent string to use for searches. WWW::Search::Minonova object's ua()
method for details.
debug
{ debug => 1 }
Optional. Turn on debuggin messages from WWW::Search::Minonova object. See WWW::Search::Minonova object's debug()
method for details. Note: the debug
argument to the component's contstructor must also be set to a true value in order for this option to work.
session
{ session => $some_other_session_ref }
{ session => 'printer' }
{ session => $session->ID }
Optional. An alternative session alias, reference or ID that the response should be sent to, defaults to sending session.
user defined values
{
_something => 'foo',
_something_else => \@bars,
}
Optional. Any argument starting with a _
(underscore) character will not affect the component but will be passed intact along with the search results when the search is completed. See OUTPUT section below for details.
shutdown
$poe_kernel->post( 'mini' => 'shutdown' );
Takes no arguments. Shuts down the component.
OUTPUT
Whether the OO or POE API is used the component passes responses back via a POE event. ARG0
will be a hashref with the following key/value pairs:
sub mini {
my ( $kernel, $results ) = @_[ KERNEL, ARG0 ];
if ( $results->{error} ) {
print "ZOMG! An error: $results->{error}\n";
}
else {
use Data::Dumper;
print Dumper( $results->{out} );
}
print $results->{_arbitrary_value}, "\n";
$kernel->post( 'mini' => 'shutdown' );
undef;
}
out
Search results. If an error occured it will be undef
and error
key will be set explaining the reason. The format of the value is the same as the return value of WWW::Search::Minonova object's search
method. See WWW::Search::Minonova object's search
method for detailed explanation.
error
If an error occured during the search this key will be present and will contain the error message.
user defined values
All of the arguments starting with _
(underscore) character will also be present in the return with their values intact.
SEE ALSO
AUTHOR
Zoffix Znet, <zoffix@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2008 by Zoffix Znet
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.