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

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