package POE::Component::WWW::Lipsum; use warnings; use strict; our $VERSION = '0.0102'; use POE; use base 'POE::Component::NonBlockingWrapper::Base'; use WWW::Lipsum; sub _methods_define { return ( generate => '_wheel_entry' ); } sub generate { $poe_kernel->post( shift->{session_id} => generate => @_ ); } sub _prepare_wheel { my $self = shift; $self->{obj} = WWW::Lipsum->new; } sub _process_request { my ( $self, $req_ref ) = @_; eval { $req_ref->{lipsum} = [ $self->{obj}->generate( %{ $req_ref->{args} } ) ]; }; if ( $@ ) { $req_ref->{lipsum} = [ "Error: $@" ]; } if ( substr($req_ref->{lipsum}[0], 0, 5) eq 'Error' ) { $req_ref->{error} = $req_ref->{lipsum}[0]; delete $req_ref->{lipsum}; } } 1; __END__ =head1 NAME POE::Component::WWW::Lipsum - non-blocking wrapper around WWW::Lipsum =head1 SYNOPSIS use strict; use warnings; use POE qw/Component::WWW::Lipsum/; my $poco = POE::Component::WWW::Lipsum->spawn; POE::Session->create( package_states => [ main => [qw/_start lipsum/] ], ); $poe_kernel->run; sub _start { $poco->generate({ event => 'lipsum', args => { amount => 5, what => 'paras', start => 'no', html => 1 }, } ); } sub lipsum { my $in_ref = $_[ARG0]; print "$_\n" for @{ $in_ref->{lipsum} }; $poco->shutdown; } Using event based interface is also possible of course. =head1 DESCRIPTION The module is a non-blocking wrapper around L which provides interface to retrieve lipsum text from L =head1 CONSTRUCTOR =head2 C my $poco = POE::Component::WWW::Lipsum->spawn; POE::Component::WWW::Lipsum->spawn( alias => 'lipsum', options => { debug => 1, trace => 1, # POE::Session arguments for the component }, debug => 1, # output some debug info ); The C method returns a POE::Component::WWW::Lipsum object. It takes a few arguments, I. The possible arguments are as follows: =head3 C ->spawn( alias => 'lipsum' ); B. Specifies a POE Kernel alias for the component. =head3 C ->spawn( options => { trace => 1, default => 1, }, ); B. A hashref of POE Session options to pass to the component's session. =head3 C ->spawn( debug => 1 ); When set to a true value turns on output of debug messages. B C<0>. =head1 METHODS =head2 C $poco->generate( { event => 'event_for_output', args => { amount => 5, what => 'paras', start => 'no', html => 1, }, _blah => 'pooh!', session => 'other', } ); Takes a hashref as an argument, does not return a sensible return value. See C event's description for more information. =head2 C my $poco_id = $poco->session_id; Takes no arguments. Returns component's session ID. =head2 C $poco->shutdown; Takes no arguments. Shuts down the component. =head1 ACCEPTED EVENTS =head2 C $poe_kernel->post( lipsum => generate => { event => 'event_for_output', args => { amount => 5, what => 'paras', start => 'no', html => 1, }, _blah => 'pooh!', session => 'other', } ); Instructs the component to fetch some Lorem Ipsum text from L. Takes a hashref as an argument, the possible keys/value of that hashref are as follows: =head3 C { event => 'results_event', } B. Specifies the name of the event to emit when results are ready. See OUTPUT section for more information. =head3 C { args => { amount => 5, what => 'paras', start => 'no', html => 1, }, } B. The C key takes a hashref as its value. This hashref will be directly dereferenced into L C method. See documentation for L for possible arguments. =head3 C { session => 'other' } { session => $other_session_reference } { session => $other_session_ID } B. Takes either an alias, reference or an ID of an alternative session to send output to. =head3 user defined { _user => 'random', _another => 'more', } B. Any keys starting with C<_> (underscore) will not affect the component and will be passed back in the result intact. =head2 C $poe_kernel->post( lipsum => 'shutdown' ); Takes no arguments. Tells the component to shut itself down. =head1 OUTPUT $VAR1 = { 'args' => { 'amount' => 2, 'html' => 1, 'what' => 'paras', 'start' => 'no' }, 'lipsum' => [ '

Lipsum text here

', '

Lipsum text here (cut for brevity)

', ], _user => 'defined args', }; The event handler set up to handle the event which you've specified in the C argument to C method/event will recieve input in the C<$_[ARG0]> in a form of a hashref. The possible keys/value of that hashref are as follows: =head2 C { 'lipsum' => [ '

Lipsum text here

', '

Lipsum text here (cut for brevity)

', ], } The C key will contain an I elements of which will be the generated Lorem Ipsum text. Note: if an error occured the C key will B be present. See C below. =head2 C { 'error' => 'Error: message', }, In case of an error the L key will not be present and an C key will be present instead which will contain an error message describing the problem. B at the time of this writing there is a minor bug in L due to which any errors related to L will not return an appropriate error message, just the text "Error: ". The bug report has been posted and may be fixed already. =head2 C 'args' => { 'amount' => 2, 'html' => 1, 'what' => 'paras', 'start' => 'no' }, The C key will contain the same hashref that you passed to C event/method C argument. =head2 user defined { '_blah' => 'foos' } Any arguments beginning with C<_> (underscore) passed into the C event/method will be present intact in the result. =head1 SEE ALSO L, L =head1 AUTHOR Zoffix Znet, C<< >> (L, L) =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc POE::Component::WWW::Lipsum You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 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. =cut