# Generated by Pod::WikiDoc version 0.18

=pod

=head1 NAME

POE::Component::Client::NNTP::Tail - Sends events for new articles posted to an NNTP newsgroup

=head1 VERSION

This documentation describes version 0.01.

=head1 SYNOPSIS

   use POE qw( Component::Client::NNTP::Tail );
   use Email::Simple;
 
   POE::Component::Client::NNTP::Tail->spawn(
     NNTPServer  => 'nntp.perl.org',
     Group       => 'perl.cpan.testers',
   );
 
   POE::Session->create(
     package_states => [
       main => [qw(_start new_header got_article)]
     ],
   );
 
   POE::Kernel->run;
 
   # register for NNTP tail events
   sub _start {
     $_[KERNEL]->post( 'perl.cpan.testers' => 'register' );
     return;
   }
 
   # get articles with subject 'FAIL' as 'got_article' events
   sub new_header {
     my ($article_id, $lines) = @_[ARG0, ARG1];
     my $article = Email::Simple->new( join("\r\n", @$lines) );
     if ( $article->header('Subject') =~ /^FAIL/ ) {
       $_[KERNEL]->post( 
         'perl.cpan.testers' => 'get_article' => $article_id 
       );
     }
     return;
   }
 
   # find and print perl version components to terminal
   sub got_article {
     my ($article_id, $lines) = @_[ARG0, ARG1];
     for my $text ( reverse @$lines ) {
       if ( $text =~ /^Summary of my perl5 \(([^)]+)\)/ ) {
         print "$1\n";
         last;
       }
     }
     return;
   }

=head1 DESCRIPTION

This component periodically polls an NNTP newsgroup and posts POE events to
component listeners as new articles are available.  These events contains the
article ID and header text for the given articles.  This component also
facilitates retrieving the full text of a particular article of interest.

Internally, it uses L<POE::Component::Client::NNTP> to manage the NNTP session.

=head1 USAGE

Spawn a new component session for each newsgroup to follow. Send the
C<<< register >>> event to specify an event to sent back when new articles arrive.
Handle the new article event. Optionally, send the C<<< get_article >>> event to 
request the full text of the article.

=head2 spawn

   POE::Component::Client::NNTP::Tail->spawn(
     NNTPServer  => 'nntp.perl.org',
     Group       => 'perl.cpan.testers',
   );

The C<<< spawn >>> class method launches a new POE::Session to follow a given
newsgroup.  The C<<< NNTPServer >>> and C<<< Group >>> arguments are required, all other
arguments are optional:

=over

=item *

NNTPServer (required) -- name or IP address of the NNTP server

=item *

Group (required) -- newsgroup to follow

=item *

Interval -- minimum number of seconds between checks for new messages
(defaults to 60)

=item *

Alias -- POE::Session alias name (defaults to the newsgroup name)

=item *

Port -- server port for NNTP connections

=item *

LocalAddr -- local address for outbound IP connection

=item *

Debug -- if true, a trace of events and arguments will be printed to STDERR

=back

You must spawn multiple times to follow multiple newsgroups.

=head1 INPUT EVENTS

The component will respond to the following events.

=head2 register

   $_[KERNEL]->post( 'perl.cpan.testers' => register => $event_name );

This event notifies the component to post a C<<< new_header >>> event to the sender
when new articles arrive.  The event will be sent using the C<<< $event_name >>>
provided, or will default to 'new_header'.  Multiple sessions may register
with a single POE::Component::Client::NNTP::Tail session.

=head2 unregister

   $_[KERNEL]->post( 'perl.cpan.testers' => unregister );

This event will stop the component from posting new_header events to the
sender.

=head2 get_article

   $_[KERNEL]->post( 
     'perl.cpan.testers' => get_article => $article_id => $event_name
   );

This event requests that the full text of C<<< $article_id >>> be returned in a
C<<< got_article >>> event.  The event will be sent using the C<<< $event_name >>>
provided, or will default to 'got_article'.

=head2 shutdown

   $_[KERNEL]->post( 'perl.cpan.testers' => 'shutdown' );

This event requests that the component stop broadcasting events, 
disconnect from the NNTP server and generally stop processing.

=head1 OUTPUT EVENTS

The component sends the following events types, though the actual event
name may be different depending on what is specified in the C<<< register >>> and
C<<< get_article >>> events.

=head2 new_header

   ($article_id, $lines) = @_[ARG0, ARG1];

The C<<< new_header >>> event is sent when new articles are found in the newsgroup.
The C<<< $lines >>> argument is a reference to an array of lines that contain the
article header.  Lines have had newlines removed.

=head2 got_article

   ($article_id, $lines) = @_[ARG0, ARG1];

The C<<< got_article >>> event is sent when the full text of an article is retrieved.
The C<<< $lines >>> argument is a reference to an array of lines that contain the full
article, including header and body text.  Lines have had newlines removed.

=head1 BUGS

Please report any bugs or feature using the CPAN Request Tracker.  
Bugs can be submitted through the web interface at 
L<http://rt.cpan.org/Dist/Display.html?Queue=POE-Component-Client-NNTP-Tail>

When submitting a bug or request, please include a test-file or a patch to an
existing test-file that illustrates the bug or desired feature.

=head1 SEE ALSO

=over

=item *

L<POE>

=item *

L<POE::Component::Client::NNTP>

=back

=head1 AUTHOR

David A. Golden (DAGOLDEN)

Portions based on or inspired by code in
POE::Component::SmokeBox::Uploads::NNTP by Chris Williams.

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2008 by David A. Golden. All rights reserved.

Licensed under Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
A copy of the License was distributed with this file or you may obtain a 
copy of the License from http:E<sol>E<sol>www.apache.orgE<sol>licensesE<sol>LICENSE-2.0

Files produced as output though the use of this software, shall not be
considered Derivative Works, but shall be considered the original work of the
Licensor.

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


