blib/lib/POE/Component/SmokeBox/Uploads/NNTP.pm

filter: Statementstmt 83.3% 75 / 90 Branchbran 50.0% 11 / 22 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 78.9% 15 / 19 Podpod 100% 3 / 3 totaltotal 74.6% 106 / 142 CC 17 SCAR 13.1
CC
17
Cov
75%
_start
7.1
spawn
6.4
_nntp_211
5.0
CRAP 3.7
↑ Summary
1 package POE::Component::SmokeBox::Uploads::NNTP;
2 2 $POE::Component::SmokeBox::Uploads::NNTP::VERSION = '1.02';
3 #ABSTRACT: Obtain uploaded CPAN modules via NNTP.
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use POE qw(Component::Client::NNTP);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Email::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub spawn {
Subroutine spawn: called CC=6 SCAR=18.6
Pod documented
12 1 my $package = shift;
13 1 my %opts = @_;
14 1 $opts{lc $_} = delete $opts{$_} for keys %opts;
15 1 ▶ croak "$package requires an 'event' argument\n" unless $opts{event};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"event"} 0 1 1
16 1 ▶ $opts{nntp} = 'nntp.perl.org' unless $opts{nntp};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"nntp"} 0 1 1
17 1 ▶ $opts{group} = 'perl.cpan.uploads' unless $opts{group};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"group"} 1 0 1
18 1 my $options = delete $opts{options};
19 1 my $self = bless \%opts, $package;
20 1 ▶ $self->{session_id} = POE::Session->create(
Branch: 1 branch
BranchTrueFalseTotal
ref $options eq 'HASH' ? : 1 0 1
21 object_states => [
22 $self => { shutdown => '_shutdown',
23 connect => '_connect',
24 poll => '_poll',
25 nntp_registered => '_nntp_registered',
26 nntp_socketerr => '_nntp_socketerr',
27 nntp_disconnected => '_nntp_disconnected',
28 nntp_200 => '_nntp_200',
29 nntp_211 => '_nntp_211',
30 nntp_220 => '_nntp_220',
31 },
32 $self => [ qw(_start _dispatch) ],
33 ],
34 heap => $self,
35 ( ref($options) eq 'HASH' ? ( options => $options ) : () ),
36 )->ID();
37 1 return $self;
38 }
39  
40 0 ▶sub session_id {
Subroutine session_id: not called CC=1 SCAR=6.9
Pod documented
41 0 return $_[0]->{session_id};
42 }
43  
44 0 ▶sub shutdown {
Subroutine shutdown: not called CC=1 SCAR=6.9
Pod documented
45 0 my $self = shift;
46 0 $poe_kernel->post( $self->{session_id}, 'shutdown' );
47 0 return;
48 }
49  
50 1 ▶sub _shutdown {
Subroutine _shutdown: called CC=3 SCAR=11.0
51 1 my ($kernel,$self) = @_[KERNEL,OBJECT];
52 1 $kernel->alias_remove( $_ ) for $kernel->alias_list();
53 1 ▶ $kernel->refcount_decrement( $self->{session_id}, __PACKAGE__ ) unless $self->{alias};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"alias"} 1 0 1
54 1 $kernel->refcount_decrement( $self->{sender_id}, __PACKAGE__ );
55 1 $kernel->post( $self->{nntpclient}->session_id(), 'shutdown' );
56 1 return;
57 }
58  
59 1 ▶sub _start {
Subroutine _start: called CC=5 SCAR=19.5
60 1 my ($kernel,$session,$sender,$self) = @_[KERNEL,SESSION,SENDER,OBJECT];
61 1 $self->{session_id} = $session->ID();
62 1 ▶ if ( $kernel == $sender and !$self->{session} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kernel == $sender and not $self->{"session"}) 0 1 1
Condition33%1/3
$kernel == $sender and not $self->{"session"}
!ll&&!rl&&r
100
MC/DC0%0/2
$kernel == $sender and not $self->{"session"}
$kernel == $sender not $self->{"session"}
Truth table33%1/3
A and not(B)
A= $kernel == $senderB= not $self->{"session"}
ABresult
0X0
100
111
63 0 croak "Not called from another POE session and 'session' wasn't set\n";
64 }
65 1 my $sender_id;
66 1 ▶ if ( $self->{session} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'session'}) { } 0 1 1
67 0 ▶ if ( my $ref = $kernel->alias_resolve( $self->{session} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $kernel->alias_resolve($self->{'session'})) { } 0 0 0
68 0 $sender_id = $ref->ID();
69 }
70 else {
71 0 croak "Could not resolve 'session' to a valid POE session\n";
72 }
73 }
74 else {
75 1 $sender_id = $sender->ID();
76 }
77 1 $kernel->refcount_increment( $sender_id, __PACKAGE__ );
78 1 $self->{sender_id} = $sender_id;
79 $self->{nntpclient} = POE::Component::Client::NNTP->spawn( 'nntp' . $self->{session_id},
80 1 { NNTPServer => $self->{nntp}, Port => $self->{nntp_port} } );
81 1 return;
82 }
83  
84 1 ▶sub _nntp_registered {
Subroutine _nntp_registered: called CC=1 SCAR=0.0
85 1 my ($kernel,$self,$sender) = @_[KERNEL,OBJECT,SENDER];
86 1 $kernel->yield( 'connect', $sender->ID() );
87 1 return;
88 }
89  
90 1 ▶sub _connect {
Subroutine _connect: called CC=1 SCAR=0.0
91 1 my ($kernel,$self,$sender) = @_[KERNEL,OBJECT,ARG0];
92 1 $kernel->post( $sender, 'connect' );
93 1 return;
94 }
95  
96 0 ▶sub _nntp_socketerr {
Subroutine _nntp_socketerr: not called CC=1 SCAR=6.9
97 0 my ($kernel,$self,$sender,$error) = @_[KERNEL,OBJECT,SENDER,ARG0];
98 0 warn "Socket error: $error\n";
99 0 $kernel->delay( 'connect', 60, $sender->ID() );
100 0 return;
101 }
102  
103 0 ▶sub _nntp_disconnected {
Subroutine _nntp_disconnected: not called CC=1 SCAR=6.9
104 0 my ($kernel,$self,$sender) = @_[KERNEL,OBJECT,SENDER];
105 0 $kernel->delay( 'connect', 60, $sender->ID() );
106 0 return;
107 }
108  
109 3 ▶sub _poll {
Subroutine _poll: called CC=1 SCAR=0.0
110 3 my ($kernel,$self) = @_[KERNEL,OBJECT];
111 3 $kernel->post ( $self->{nntpclient}->session_id(), 'group', $self->{group} );
112 3 undef;
113 }
114  
115 1 ▶sub _nntp_200 {
Subroutine _nntp_200: called CC=1 SCAR=0.0
116 1 my ($kernel,$self) = @_[KERNEL,OBJECT];
117 1 $kernel->yield( 'poll' );
118 1 undef;
119 }
120  
121 2 ▶sub _nntp_211 {
Subroutine _nntp_211: called CC=5 SCAR=16.2
122 2 my ($kernel,$self,$sender) = @_[KERNEL,OBJECT,SENDER];
123 2 my ($estimate,$first,$last,$group) = split( /\s+/, $_[ARG0] );
124  
125 2 ▶ if ( defined $self->{articles}->{ $group } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'articles'}{$group}) { } 1 1 2
126 # Check for new articles
127 1 ▶ if ( $estimate >= $self->{articles}->{ $group } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($estimate >= $self->{"articles"}{$group}) 1 0 1
128 1 for my $article ( $self->{articles}->{ $group } .. $estimate ) {
129 1 $kernel->post ( $sender => article => $article );
130 }
131 1 $self->{articles}->{ $group } = $estimate + 1;
132 }
133 }
134 else {
135 1 $self->{articles}->{ $group } = $estimate + 1;
136 }
137 2 ▶ $kernel->delay( 'poll' => ( $self->{poll} || 60 ) );
Condition50%1/2
$self->{'poll'} || 60
l!l
20
MC/DC0%0/1
$self->{'poll'} || 60
$self->{'poll'}
Truth table50%1/2
A
A= $self->{'poll'}
Aresult
11
00
138 2 undef;
139 }
140  
141 1 ▶sub _nntp_220 {
Subroutine _nntp_220: called CC=2 SCAR=7.0
142 1 my ($kernel,$self,$text) = @_[KERNEL,OBJECT,ARG0];
143 1 my $article = Email::Simple->new( join "\n", @{ $_[ARG1] } );
144 1 my $subject = $article->header('Subject');
145 1 ▶ if ( my ($upload) = $subject =~ m!^CPAN Upload:\s+(\w+/\w+/\w+/.+(\.tar\.(gz|bz2)|\.tgz|\.zip))$!i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($upload) = $subject =~ m[^CPAN Upload:\s+(\w+/\w+/\w+/.+(\.tar\.(gz|bz2)|\.tgz|\.zip))$]i) 1 0 1
146 1 $kernel->call( $self->{session_id}, '_dispatch', $upload );
147 }
148 1 return;
149 }
150  
151 1 ▶sub _dispatch {
Subroutine _dispatch: called CC=1 SCAR=0.0
152 1 my ($kernel,$self,$module) = @_[KERNEL,OBJECT,ARG0];
153 1 $kernel->post( $self->{sender_id}, $self->{event}, $module );
154 1 return;
155 }
156  
157 2 1;
158  
159 __END__
↑ Summary