blib/lib/POE/Component/WakeOnLAN.pm

filter: Statementstmt 94.1% 64 / 68 Branchbran 43.7% 7 / 16 Conditioncond 36.3% 4 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 76.1% 86 / 113 CC 15 SCAR 19.0
CC
15
Cov
79%
wake_up
11.7
_start
7.5
_ready
2.0
CRAP 6.7
↑ Summary
1 package POE::Component::WakeOnLAN;
2 {
3 2 $POE::Component::WakeOnLAN::VERSION = '1.04';
4 }
5  
6 #ABSTRACT: A POE Component to send packets to power on computers.
7  
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Net::IP::Minimal;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶sub wake_up {
Subroutine wake_up: called CC=9 SCAR=24.6
Pod documented
17 1 my $package = shift;
18 1 my %params = @_;
19 1 $params{lc $_} = delete $params{$_} for keys %params;
20 1 ▶ croak "$package wake_up requires a 'macaddr' parameter\n" unless $params{macaddr};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"macaddr"} 0 1 1
21 1 ▶ croak "$package wake_up requires an 'event' parameter\n" unless $params{event};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"event"} 0 1 1
22 1 $params{macaddr} =~ s/://g;
23 1 ▶ $params{port} = 9 unless $params{port} and $params{port} =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"port"} and $params{"port"} =~ /^\d+$/ 1 0 1
Condition33%1/3
$params{"port"} and $params{"port"} =~ /^\d+$/
!ll&&!rl&&r
100
MC/DC0%0/2
$params{"port"} and $params{"port"} =~ /^\d+$/
$params{"port"} $params{"port"} =~ /^\d+$/
Truth table33%1/3
A and B
A= $params{"port"}B= $params{"port"} =~ /^\d+$/
ABresult
0X0
100
111
24 1 ▶ $params{address} = '255.255.255.255' unless $params{address} and Net::IP::Minimal::ip_get_version( $params{address} );
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"address"} and Net::IP::Minimal::ip_get_version($params{"address"}) 1 0 1
Condition33%1/3
$params{"address"} and Net::IP::Minimal::ip_get_version($params{"address"})
!ll&&!rl&&r
100
MC/DC0%0/2
$params{"address"} and Net::IP::Minimal::ip_get_version($params{"address"})
$params{"address"} Net::IP::Minimal::ip_get_version($params{"address"})
Truth table33%1/3
A and B
A= $params{"address"}B= Net::IP::Minimal::ip_get_version($params{"address"})
ABresult
0X0
100
111
25 1 my $options = delete $params{options};
26 1 my $self = bless \%params, $package;
27 1 ▶ $self->{session_id} = POE::Session->create(
Branch: 1 branch
BranchTrueFalseTotal
ref $options eq 'HASH' ? : 0 1 1
28 object_states => [
29 $self => [qw(_start _ready)],
30 ],
31 heap => $self,
32 ( ref($options) eq 'HASH' ? ( options => $options ) : () ),
33 )->ID();
34 1 return $self;
35 }
36  
37 1 ▶sub _start {
Subroutine _start: called CC=6 SCAR=20.1
38 1 my ($kernel,$self,$sender) = @_[KERNEL,OBJECT,SENDER];
39 1 $self->{session_id} = $_[SESSION]->ID();
40 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
41 0 croak "Not called from another POE session and 'session' wasn't set\n";
42 }
43 1 my $sender_id;
44 1 my $session = delete $self->{session};
45 1 ▶ if ( $session ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($session) { } 0 1 1
46 0 ▶ if ( my $ref = $kernel->alias_resolve( $self->{session} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $kernel->alias_resolve($self->{'session'})) { } 0 0 0
47 0 $sender_id = $ref->ID();
48 }
49 else {
50 0 croak "Could not resolve 'session' to a valid POE session\n";
51 }
52 }
53 else {
54 1 $sender_id = $sender->ID();
55 }
56 1 $kernel->refcount_increment( $sender_id, __PACKAGE__ );
57 1 $self->{sender_id} = $sender_id;
58 1 ▶ my $sock = new IO::Socket::INET(Proto=>'udp') || return;
Condition50%1/2
'IO::Socket::INET'->new('Proto', 'udp') || (return)
l!l
10
MC/DC0%0/1
'IO::Socket::INET'->new('Proto', 'udp') || (return)
'IO::Socket::INET'->new('Proto', 'udp')
Truth table50%1/2
A
A= 'IO::Socket::INET'->new('Proto', 'udp')
Aresult
11
00
59 1 my $ip_addr = inet_aton( $self->{address} );
60 1 my $sock_addr = sockaddr_in($self->{port}, $ip_addr);
61 1 my $packet = pack('C6H*', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, $self->{macaddr} x 16);
62 1 $kernel->select_write( $sock, '_ready' );
63 1 setsockopt($sock, SOL_SOCKET, SO_BROADCAST, 1);
64 1 send($sock, $packet, 0, $sock_addr);
65 1 return;
66 }
67  
68 1 ▶sub _ready {
Subroutine _ready: called CC=2 SCAR=6.9
69 1 my ($kernel,$self,$socket) = @_[KERNEL,OBJECT,ARG0];
70 1 $kernel->select_write( $socket );
71 1 my $response = { };
72 1 $response->{$_} = $self->{$_} for keys %{ $self };
73 1 delete $response->{session_id};
74 1 my $sender_id = delete $response->{sender_id};
75 1 my $event = delete $response->{event};
76 1 $kernel->post( $sender_id, $event, $response );
77 1 $kernel->refcount_decrement( $sender_id, __PACKAGE__ );
78 1 return;
79 }
80  
81 2 1;
82  
83  
84 __END__
↑ Summary