Net-LastFM-Submission
view release on metacpan or search on metacpan
examples/poe_client.pl view on Meta::CPAN
#!/usr/bin/perl
use strict;
use utf8;
use lib qw(../lib ..);
BEGIN { $ENV{'SUBMISSION_DEBUG'}++ };
use POE qw(Component::Client::HTTP);
use POE::Component::Net::LastFM::Submission 0.24; # support an existing client
use Data::Dumper;
my $conf = require '.lastfmrc';
POE::Component::Client::HTTP->spawn(
Alias => 'HTTP_CLIENT',
Agent => 'My http client/1.0',
Timeout => 1,
# ...
);
POE::Component::Net::LastFM::Submission->spawn(
Alias => 'LASTFM_SUBMIT',
Client => 'HTTP_CLIENT', # use my own client
LastFM => {map { $_ => $conf->{$_} } 'user', 'password'},
);
POE::Session->create(
options => { trace => 1 },
inline_states => {
_start => sub {
$_[KERNEL]->post('LASTFM_SUBMIT' => 'handshake' => 'np');
$_[KERNEL]->yield('_delay');
},
_delay => sub { $_[KERNEL]->delay($_[STATE] => 5) },
np => sub {
warn Dumper @_[ARG0, ARG1, ARG2];
$_[HEAP]->{__i}++ == 10
?
$_[KERNEL]->post(
'LASTFM_SUBMIT' => 'submit' => 'sb',
{'artist' => 'ArtistName', 'title' => 'TrackName', time => time - 10*60}
)
:
$_[KERNEL]->post(
'LASTFM_SUBMIT' => 'now_playing' => 'np',
{'artist' => 'ÐÑÑиÑÑ11', 'title' => 'ÐеÑнÑ21'},
$_[HEAP]->{__i}
)
;
},
sb => sub {
warn Dumper $_[ARG0];
$_[KERNEL]->stop;
},
}
);
POE::Kernel->run;
__END__
=head1 NAME
examples/poe_client.pl - the example of usage POE::Component::Net::LastFM::Submission
=head1 SYNOPSIS
cd examples; ./poe_client.pl
=head1 DESCRIPTION
( run in 2.340 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )