The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

POE::Component::Net::LastFM::Submission - non-blocking wrapper around Net::LastFM::Submission

SYNOPSIS

    use strict;
    use POE qw(Component::Net::LastFM::Submission);
    use Data::Dumper;
    
    POE::Component::Net::LastFM::Submission->spawn(
        Alias  => 'LASTFM_SUBMIT',
        LastFM => {
            user     => 'net_lastfm',
            password => '12',
       },
    );
    
    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..$#_];
                $_[KERNEL]->post(
                    'LASTFM_SUBMIT' => 'now_playing' => 'np',
                    {'artist' => 'ArtistName', 'title'  => 'TrackTitle'},
                    'job_id'
                );
            },
        }
    );
    
    POE::Kernel->run;

DESCRIPTION

The module is a non-blocking wrapper around Net::LastFM::Submission module, it is truelly asynchronously. Net::LastFM::Submission contains methods for generate requests and parse response (version >= 0.5). See documentation Net::LastFM::Submission.

POE::Component::Net::LastFM::Submission start own POE::Component::Client::HTTP when the user didn't supply the parameter Client. It lets other sessions run while HTTP transactions are being processed, and it lets several HTTP transactions be processed in parallel.

METHODS

spawn

    POE::Component::Net::LastFM::Submission->spawn(
        Alias  => 'LASTFM_SUBMIT',
        LastFM => {
            user     => 'net_lastfm',
            password => '12',
        },
    );
    
    # or
    
    POE::Component::Client::HTTP->spawn(
       Alias => 'HTTP_CLIENT',
       ...
    );

    POE::Component::Net::LastFM::Submission->spawn(
       Alias  => 'LASTFM_SUBMIT',
       Client => 'HTTP_CLIENT', # alias or session id of PoCo::Client::HTTP
       LastFM => {
           user     => 'net_lastfm',
           password => '12',
       },
    );

PoCo::Net::LastFM::Submission's spawn method takes a few named parameters:

  • Alias

    Alias sets the name by which the session will be known. If no alias is given, the component defaults is LASTFM_SUBMISSION. The alias lets several sessions interact with HTTP components without keeping (or even knowing) hard references to them. It's possible to spawn several Submission components with different names.

    This is a constructor for Net::LastFM::Submission object. It takes list of parameters or hashref parameter.

  • LastFM

    The data for Net::LastFM::Submission constructor. It's hashref of data. Required. See Net::LastFM::Submission.

  • Client

    The alias or session id of an existing PoCo::Client::HTTP. Optional. See POE::Component::Client::HTTP.

  • Agent

    The user agent of the client. Optional. It is a agent of own PoCo::Client::HTTP. See POE::Component::Client::HTTP.

  • Timeout

    The timeout of the client. Optional. It is a timeout of own PoCo::Client::HTTP. See POE::Component::Client::HTTP.

ACCEPTED EVENTS

Sessions communicate asynchronously with PoCo::Net::LastFM::Submission. They post requests to it, and it posts responses back.

Events have syntax like PoCo::Client::HTTP.

First param is a alias of submission session.

Second param is accepted event such as handshake, now_playing and submit.

Third param is a event for return after execute request.

Forth param is hashref param for the accepted event (for real method of Net::LastFM::Submission).

Fiveth param is a tag to identify the request.

handshake

    $_[KERNEL]->post('LASTFM_SUBMIT' => 'handshake' => 'np');

now_playing

     $_[KERNEL]->post(
        'LASTFM_SUBMIT' => 'now_playing' => 'np',
        {'artist' => 'ArtistName', 'title'  => 'TrackTitle'}, # params of now_playing
        'job_id'
    );

See params of now_playing in Net::LastFM::Submission.

submit

    $_[KERNEL]->post(
        'LASTFM_SUBMIT' => 'submit' => 'sb',
        {'artist' => 'ArtistName', 'title'  => 'TrackTitle', 'time'   => time - 10*60}, # params of submit
        'job_id'
    );

See params of submit in Net::LastFM::Submission.

TRACE MODE

The module supports trace mode - trace POE session.

    BEGIN { $ENV{SUBMISSION_TRACE}++ };
    use POE::Component::Net::LastFM::Submission;

EXAMPLES

See examples/poe*.pl in this distributive.

SEE ALSO

POE Net::LastFM::Submission

DEPENDENCIES

Net::LastFM::Submission POE::Component::Client::HTTP POE::Session Carp

AUTHOR

Anatoly Sharifulin, <sharifulin at gmail.com>

BUGS

Please report any bugs or feature requests to bug-net-lastfm-submission at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-LastFM-Submission. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT & DOCUMENTATION

You can find documentation for this module with the perldoc command.

    perldoc Net::LastFM::Submission
    perldoc POE::Component::Net::LastFM::Submission

You can also look for information at:

COPYRIGHT & LICENSE

Copyright (C) 2009 Anatoly Sharifulin

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.