File Coverage

blib/lib/POE/Component/WWW/CPANRatings/RSS.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1             package POE::Component::WWW::CPANRatings::RSS;
2              
3 1     1   257365 use warnings;
  1         2  
  1         32  
4 1     1   5 use strict;
  1         1  
  1         44  
5              
6             our $VERSION = '0.0101';
7              
8 1     1   5 use POE;
  1         5  
  1         8  
9 1     1   344 use base 'POE::Component::NonBlockingWrapper::Base';
  1         2  
  1         96  
10 1     1   411 use WWW::CPANRatings::RSS;
  0            
  0            
11              
12             sub _methods_define {
13             return (
14             fetch => '_wheel_entry',
15             stop_repeat => '_stop_repeat',
16             );
17             }
18              
19             sub fetch {
20             $poe_kernel->post( shift->{session_id} => fetch => @_ );
21             }
22              
23             sub stop_repeat {
24             $poe_kernel->call( shift->{session_id} => stop_repeat => @_ );
25             }
26              
27             sub _stop_repeat {
28             my ( $kernel, $self, $repeat_name ) = @_[ KERNEL, OBJECT, ARG0 ];
29             return
30             unless exists $self->{timers}{ $repeat_name };
31              
32             $kernel->refcount_decrement(
33             $self->{timers}{ $repeat_name }{session}
34             =>'POE::Component::NonBlockingWrapper::Base'
35             );
36              
37             $kernel->alarm_remove( $_ )
38             for @{ $self->{timers}{ $repeat_name }{timers} };
39              
40             delete $self->{timers}{ $repeat_name };
41             }
42              
43             sub _prepare_wheel {
44             my $self = shift;
45             $self->{obj} = WWW::CPANRatings::RSS->new(
46             $self->{ua} ? ( ua => $self->{ua} ) : ()
47             );
48             }
49              
50             sub _process_request {
51             my ( $self, $req_ref ) = @_;
52              
53             my $method = $req_ref->{unique} ? 'fetch_unique' : 'fetch';
54             my $ratings_ref = $self->{obj}->$method(
55             $method eq 'fetch_unique' ? $req_ref->{file} : ()
56             );
57              
58             if ( $ratings_ref ) {
59             $req_ref->{ratings} = $ratings_ref;
60             delete $req_ref->{error};
61             }
62             else {
63             $req_ref->{error} = $self->{obj}->error;
64             }
65             }
66              
67             sub _child_stdout {
68             my ( $kernel, $self, $input ) = @_[ KERNEL, OBJECT, ARG0 ];
69              
70             delete $input->{session};
71             my $session = delete $input->{sender};
72             my $event = delete $input->{event};
73              
74             if ( $input->{repeat} ) {
75             my $repeat_name = $input->{repeat_name} || 'GENERAL';
76            
77             $kernel->refcount_increment( $session =>'POE::Component::NonBlockingWrapper::Base' );
78              
79             if ( exists $self->{timers}{ $repeat_name } ) {
80             $kernel->refcount_decrement( $session =>'POE::Component::NonBlockingWrapper::Base' );
81             $kernel->alarm_remove( $_ )
82             for @{ $self->{timers}{ $repeat_name }{timers} || [] };
83              
84             delete $self->{timers}{ $repeat_name };
85             }
86              
87             push @{ $self->{timers}{ $repeat_name }{timers} },
88             $kernel->delay_set(
89             fetch => $input->{repeat} => {
90             %$input,
91             session => $session,
92             event => $event,
93             }
94             );
95              
96             $self->{timers}{ $repeat_name }{session} = $session;
97             }
98              
99             $kernel->post( $session, $event, $input );
100             $kernel->refcount_decrement( $session =>'POE::Component::NonBlockingWrapper::Base' );
101            
102             undef;
103             }
104              
105             sub _shutdown {
106             my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
107             for my $timer ( values %{ $self->{timers} } ) {
108             $kernel->refcount_decrement( $timer->{session} =>'POE::Component::NonBlockingWrapper::Base');
109             $kernel->alarm_remove( $_ )
110             for @{ $timer->{timers} || [] };
111             }
112             delete $self->{timers};
113             $kernel->alarm_remove_all;
114             $kernel->alias_remove( $_ ) for $kernel->alias_list;
115             $kernel->refcount_decrement( $self->{session_id} => 'POE::Component::NonBlockingWrapper::Base' )
116             unless $self->{alias};
117              
118             $self->{shutdown} = 1;
119            
120             $self->{wheel}->shutdown_stdin
121             if $self->{wheel};
122             }
123              
124             1;
125             __END__