Why not adopt me?
NAME
POE::Component::WWW::PAUSE::RecentUploads::Tail - tail recent uploads to PAUSE.
SYNOPSIS
use strict;
use warnings;
use POE qw(Component::WWW::PAUSE::RecentUploads::Tail);
POE::Component::WWW::PAUSE::RecentUploads::Tail->spawn(
login => 'PAUSE_LOGIN',
pass => 'PAUSE_PASSWORD',
store => 'data.file', # where to store old data
debug => 1,
alias => 'pause',
);
POE::Session->create(
package_states => [
main => [ qw( _start recent ) ],
],
);
$poe_kernel->run;
sub _start {
$poe_kernel->post( pause => fetch => {
event => 'recent',
interval => 600, # 10 minute interval
}
);
}
sub recent {
my $data_ref = $_[ARG0];
my $iter_time = localtime $data_ref->{time};
if ( $data_ref->{error} ) {
print "Failed on this itteration with $data_ref->{error}\n";
}
else {
my $message = @{ $data_ref->{data} }
? "\nNew uploads at $iter_time\n"
: "\nNo uploads at $iter_time\n";
print $message;
foreach my $dist ( @{ $data_ref->{data} } ) {
printf "%s by %s (size: %s)\n",
@$dist{ qw( dist name size ) };
}
}
}
Using the event based interface is also possible, of course.
DESCRIPTION
This module accesses the list of recent uploads on http://pause.perl.org and reports whichever it didn't report earlier.
CONSTRUCTOR
my $poco = POE::Component::WWW::PAUSE::RecentUploads::Tail->spawn(
login => 'PAUSE LOGIN', # mandatory
pass => 'PAUSE PASSWORD', # mandatory
);
POE::Component::WWW::PAUSE::RecentUploads::Tail->spawn(
login => 'PAUSE LOGIN', # mandatory
pass => 'PAUSE PASSWORD', # mandatory
store => 'storage_file.data', # this and all the rest are optional
alias => 'recent',
debug => 1,
ua_args => {
timeout => 10,
agent => 'RecentUA',
# other LWP::UserAgent's constructor arguments can go here
},
options => {
debug => 1, # POE::Session create() may go here.
},
);
Spawns a new POE::Component::WWW::PAUSE::RecentUploads::Tail component and returns a reference to it, but you don't have to keep it if you set the optional alias
argument. Takes a single argument which is a hashref of options. Two of them, login
and password
are mandatory, the rest is optional. The possible keys/values are as follows:
login
{ login => 'PAUSE LOGIN' }
Mandatory. Must contain your http://pause.perl.org login.
pass
{ login => 'PAUSE LOGIN' }
Mandatory. Must contain your http://pause.perl.org password.
store
{ store => 'storage_file.data' }
{ store => '/tmp/storage_file.data' }
Optional. Specifies the filename of the file where we are going to store the already reported modules. Defaults to: pause_recent.data
in the current directory.
alias
{ alias => 'recent' }
Optional. Specifies the component's POE::Session alias of the component.
debug
Optional.
Enables output of some debug messages (usually not very useful).
ua_args
{ debug => 1 }
Optional. When set to a true value will make the component emit some debuging info. Defaults to: 0
.
options
{
options => {
trace => 1,
default => 1,
}
}
A hashref of POE Session options to pass to the component's session.
METHODS
These are the object-oriented methods of the component.
fetch
$poco->fetch( { event => 'recent' } );
$poco->fetch( {
event => 'recent', # the only mandatory argument
interval => 600, # 10 minute interval
login => 'other_login', # this and below is optional
pass => 'other_pass',
session => 'other_session',
ua_args => {
timeout => 10, # default timeout is 30.
argent => 'LolFetcher',
},
_user1 => 'random',
_cow => 'meow',
}
);
Instructs the component to fetch information about recent PAUSE uploads. See fetch
event description below for more information.
stop_interval
$poco->stop_interval;
$poco->stop_interval( $req_id );
The stop_interval
method stops an already running request (which is started with fetch
method/event). The output of each itteration will contain a req_id
key (see OUTPUT section) which you may pass as an optional argument to the method. When no arguments are specified stops all currently running requests.
session_id
my $fetcher_id = $poco->session_id;
Takes no arguments. Returns POE Session ID of the component.
shutdown
$poco->shutdown;
Takes no arguments. Shuts the component down.
ACCEPTED EVENTS
The interaction with the component is also possible via event based interface. The following events are accepted by the component:
fetch
$poco->fetch( { event => 'recent' } );
$poco->fetch( {
event => 'recent', # the only mandatory argument
interval => 600, # 10 minute interval
login => 'other_login', # this and below is optional
pass => 'other_pass',
session => 'other_session',
ua_args => {
timeout => 10, # default timeout is 30.
argent => 'LolFetcher',
},
_user1 => 'random',
_cow => 'meow',
}
);
Takes one argument which is a hashref with the following keys:
event
{ event => 'event_where_to_send_output' }
Mandatory. The name of the event which to send when output is ready. See OUTPUT section for its format.
interval
{ interval => 600 }
Optional. Specifies the interval in seconds between requests to PAUSE for fresh list. If specified to 0
will make the component only fire a single shot request without setting any interval. Defaults to: 1800
(30 minutes)
session
{ session => 'other_session_alias' }
{ session => $other_session_ID }
{ session => $other_session_ref }
Optional. Specifies an alternative POE Session to send the output to. Accepts either session alias, session ID or session reference. Defaults to the current session.
login
{ login => 'some_other_login' }
Optional.Using login
argument you may override the PAUSE login you've specified in the constructor. Defaults to: contructor's login
value.
pass
{ pass => 'some_other_password' }
Optional. Using pass
argument you may override the PAUSE password you've specified in the constructor. Defaults to: contructor's pass
value.
ua_args
{
ua_args => {
timeout => 10, # defaults to 30
agent => 'SomeUA',
# the rest of LWP::UserAgent contructor arguments
},
}
Optional. The ua_args
key takes a hashref as a value which should contain the arguments which will be passed to LWP::UserAgent contructor. Note: all arguments will default to whatever LWP::UserAgent default contructor arguments are except for the timeout
, which will default to 30 seconds.
user defined arguments
{
_user_var => 'foos',
_another_one => 'bars',
_some_other => 'beers',
}
Optional. Any keys beginning with the _
(underscore) will be present in the output intact. If where
option (see below) is specified, any arguments will also be present in the result of "finished downloading" event.
stop_interval
$poe_kernel->post( recent => 'stop_interval' );
$poe_kernel->post( recent => 'stop_interval' => $req_id );
The stop_interval
method stops an already running request (which is started with fetch
method/event). The output of each itteration will contain a req_id
key (see OUTPUT section) which you may pass as an optional argument to the method. When no arguments are specified stops all currently running requests.
shutdown
$poe_kernel->post( recent => 'shutdown' );
Takes no arguments, instructs the component to shut itself down.
OUTPUT
$VAR1 = {
'data' => [
{
'name' => 'PEVANS',
'dist' => 'Socket-GetAddrInfo-0.08_6',
'size' => '11502b'
},
{
'name' => 'JROBINSON',
'dist' => 'SQL-Translator-0.0899_02',
'size' => '551090b'
},
],
'time' => 1202002776,
'req_id' => '0.27891249752520212020027750.348456874580251',
'interval' => 600,
'_user_key' => 'user_data'
};
The event handler set up to listen for the event, name of which you've specified in the event
argument of fetch
event/method will recieve the results in ARG0
in the form of a hashref with one or more of the keys presented below. The keys of the output hashref are as follows:
data
{
'data' => [
{
'name' => 'CJUKUO',
'dist' => 'AIIA-GMT-0.01',
'size' => '33428b'
},
{
'name' => 'DOMQ',
'dist' => 'Alien-Selenium-0.07',
'size' => '1640987b'
},
# more of these here
],
}
Unless an error occured, the data
key will be present and the value of it will be an arrayref of hashrefs representing recent uploads to PAUSE. The keys of those hashrefs are as follows:
name
{ 'name' => 'CJUKUO' }
The author ID of the upload. Note: often ID will show up on PAUSE a bit later than the upload itself. If author's ID is missing the component will ignore this upload and will report it later.
dist
{ 'dist' => 'Alien-Selenium-0.07' }
The name of the distro (or file if you prefer) that was uploaded.
size
{ 'size' => '1640987b' }
The size of the uploaded file. The value will also contain the unit of measure.
error
{ 'error' => '401 Authorization Required' }
If an error occured the error
key will be present and will contain the description of the error.
time
{ 'time' => 1202002776 }
my $request_time = localtime $data_ref->{time};
Will contain the output of Perl's time
function which will be the time of the request.
req_id
{ 'req_id' => '0.27891249752520212020027750.348456874580251' }
The req_id
key will contain the ID of your request. You can use in in the stop_interval()
event/method to stop your request.
interval
{ 'interval' => 600 }
The interval
key will contain the interval of request recurrance in seconds. This is basically whatever you've specified in the fetch()
event/method.
user defined arguments
{
_user_var => 'foos',
_another_one => 'bars',
_some_other => 'beers',
}
Optional. Any keys beginning with the _
(underscore) will be present in the output intact.
PREREQUISITES
This module requires the following modules/version for proper operation:
Carp => 1.04,
POE => 0.9999,
POE::Component::WWW::PAUSE::RecentUploads => 0.01,
Storable => 2.15,
Not tested with earlier versions of those modules, but it might work.
SEE ALSO
WWW::PAUSE::RecentUpload, POE::Component::WWW::PAUSE::RecentUploads, POE::Component::IRC::Plugin::PAUSE::RecentUploads, http://pause.perl.org
AUTHOR
Zoffix Znet, <zoffix at cpan.org>
BUGS
Please report any bugs or feature requests to bug-poe-component-www-pause-recentupoads-tail at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-WWW-PAUSE-RecentUpoads-Tail. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc POE::Component::WWW::PAUSE::RecentUpoads::Tail
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-WWW-PAUSE-RecentUpoads-Tail
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/POE-Component-WWW-PAUSE-RecentUpoads-Tail
CPAN Ratings
http://cpanratings.perl.org/d/POE-Component-WWW-PAUSE-RecentUpoads-Tail
Search CPAN
http://search.cpan.org/dist/POE-Component-WWW-PAUSE-RecentUpoads-Tail
COPYRIGHT & LICENSE
Copyright 2008 Zoffix Znet, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.