blib/lib/Net/SMS/MunduSMS.pm

filter: Statementstmt 55.1% 27 / 49 Branchbran 0.0% 0 / 10 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 77.7% 7 / 9 Podpod 100% 3 / 3 totaltotal 46.9% 38 / 81 CC 8 SCAR 20.5
CC
8
Cov
43%
send_sms
20.0
_login
8.3
new
2.0
CRAP 7.8
↑ Summary
1 package Net::SMS::MunduSMS;
2  
3 1 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.021';
9  
10 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
11 1 my $class = shift;
12 1 my %args = @_;
13  
14 1 ▶ $class = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
15  
16 1 my %params = %args;
17  
18 1 $params{sms} = [];
19 1 ▶ $params{mech} = WWW::Mechanize->new( onerror => sub { } );
Subroutine __ANON__: called CC=1 SCAR=0.0
20 1 $params{mech}->agent_alias('Windows IE 6');
21  
22 1 return bless \%params, $class;
23 }
24  
25 1 ▶sub _login {
Subroutine _login: called CC=4 SCAR=21.2
26 1 my $self = shift;
27  
28 1 $self->{mech}->get(q[http://www.mundusms.com/web/Login.aspx]);
29 1 $self->{mech}->form_number(1);
30  
31 0 map { $_->value( $self->{username} ); } $self->{mech}->find_all_inputs(
32 1 type => 'text',
33 name_regex => qr/user_login$/,
34 );
35  
36 0 map { $_->value( $self->{password} ); } $self->{mech}->find_all_inputs(
37 1 type => 'password',
38 name_regex => qr/user_pass$/,
39 );
40  
41 $self->{mech}->submit_form(
42 1 fields => {
43 '__EVENTARGUMENT' => '',
44 '__EVENTTARGET' => '',
45 '__LASTFOCUS' => '',
46 'ctl00$ContentPlaceHolderMasterLogin$button_login.x' => 10,
47 'ctl00$ContentPlaceHolderMasterLogin$button_login.y' => 14,
48 'ctl00$dropCulture' => 1
49 }
50 );
51  
52 0 ▶ return ( $self->{mech}->uri =~ /UserHome.aspx$/ ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'mech'}->uri =~ /UserHome.aspx$/ ? : 0 0 0
53  
54 0 ▶ return 0 unless ( $self->{mech}->find_link( url_regex => qr/sendsms.aspx/i ) && $self->{mech}->follow_link( url_regex => qr/sendsms.aspx/i ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"mech"}->find_link("url_regex", qr/sendsms.aspx/i) and $self->{"mech"}->follow_link("url_regex", qr/sendsms.aspx/i) 0 0 0
Condition0%0/3
$self->{"mech"}->find_link("url_regex", qr/sendsms.aspx/i) and $self->{"mech"}->follow_link("url_regex", qr/sendsms.aspx/i)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"mech"}->find_link("url_regex", qr/sendsms.aspx/i) and $self->{"mech"}->follow_link("url_regex", qr/sendsms.aspx/i)
$self->{"mech"}->find_link("url_regex", qr/sendsms.aspx/i) $self->{"mech"}->follow_link("url_regex", qr/sendsms.aspx/i)
Truth table0%0/3
A and B
A= $self->{"mech"}->find_link("url_regex", qr/sendsms.aspx/i)B= $self->{"mech"}->follow_link("url_regex", qr/sendsms.aspx/i)
ABresult
0X0
100
111
55 }
56  
57 0 ▶sub add_sms {
Subroutine add_sms: not called CC=1 SCAR=6.9
Pod documented
58 0 my $self = shift;
59 0 my %args = @_;
60  
61 0 push( @{ $self->{sms} }, \%args );
62  
63 0 return 1;
64 }
65  
66 0 ▶sub send_sms {
Subroutine send_sms: not called CC=4 SCAR=30.0
Pod documented
67 0 my $self = shift;
68  
69 0 ▶ $self->{logged_in} = $self->_login unless ( $self->{logged_in} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"logged_in"} 0 0 0
70  
71 0 ▶ while ( my $sms = pop( @{ $self->{sms} } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sms = pop @{$$self{"sms"};}) 0 0 0
72 0 ▶ $self->{mech}->follow_link( url_regex => qr/sendsms.aspx/i ) unless ( $self->{mech}->uri =~ /sendsms.aspx/i );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"mech"}->uri =~ /sendsms.aspx/i 0 0 0
73  
74 0 $self->{mech}->form_number(1);
75  
76 0 map { $_->value( $sms->{to} ); } $self->{mech}->find_all_inputs(
77 0 type => 'textarea',
78 name_regex => qr/mobileno$/,
79 );
80  
81 0 map { $_->value( $sms->{message} ); } $self->{mech}->find_all_inputs(
82 0 type => 'textarea',
83 name_regex => qr/msg$/,
84 );
85  
86 0 my $len = sprintf( '%d characters, %d SMS', length( $sms->{message} ), ( int( length( $sms->{message} ) ) / 160 ) + 1 );
87  
88 $self->{mech}->submit_form(
89 fields => {
90 '__EVENTARGUMENT' => '',
91 '__EVENTTARGET' => '',
92 '__LASTFOCUS' => '',
93 'ctl00$ContentPlaceHolderContent$button_submit_sms.x' => 15,
94 'ctl00$ContentPlaceHolderContent$button_submit_sms.y' => 6,
95 'ctl00$ContentPlaceHolderContent$InfoCharCounter' => $len,
96 'ctl00$ContentPlaceHolderContent$hiddenCharCount' => $len,
97 'ctl00$ContentPlaceHolderContent$Hiddenselected' => 0,
98 'ctl00$ContentPlaceHolderContent$HiddenUnicode' => 0,
99 'ctl00$ContentPlaceHolderContent$DropDown_groups' => 0,
100 'ctl00$ContentPlaceHolderContent$Cal_to_ClientStat' => '',
101 'ctl00$ContentPlaceHolderContent$HiddenScheduled_id' => '',
102 'ctl00$ContentPlaceHolderContent$Hidden_date' => '',
103 'ctl00$ContentPlaceHolderContent$Hidden_time' => '',
104 'ctl00$ContentPlaceHolderContent$Drop_repeat' => '',
105 0 'ctl00$ContentPlaceHolderContent$hidden_charcount' => length( $sms->{message} ),
106 'ctl00$ContentPlaceHolderContent$txt_date' => '',
107 'ctl00$ContentPlaceHolderContent$txt_time' => '',
108 'hiddenInputToUpdateATBuffer_CommonToolkitScripts' => 0
109 }
110 );
111 }
112  
113 0 return 1;
114 }
115  
116 1 1;
117  
118 __END__
↑ Summary