Recorder/Logger.pm

filter: Statementstmt 10.0% 11 / 110 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 15.0% 3 / 20 Podpod 0.0% 0 / 17 totaltotal 7.2% 14 / 194 CC 20 SCAR 23.4
CC
20
Cov
7%
Submit
30.0
new
12.0
Log
12.0
CRAP 10.4
« Recorder.pm ↑ Summary
1 package HTTP::Recorder::Logger;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use LWP::MemberMixin;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 our @ISA = qw( LWP::MemberMixin );
7  
8 sub new {
9 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
10  
11 0 my %args = (
12 @_
13 );
14  
15 0 ▶ my $self = bless ({}, ref ($class) || $class);
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
16  
17 0 ▶ $self->{'file'} = $args{'file'} || "/tmp/scriptfile";
Condition0%0/2
$args{'file'} || '/tmp/scriptfile'
l!l
00
MC/DC0%0/1
$args{'file'} || '/tmp/scriptfile'
$args{'file'}
Truth table0%0/2
A
A= $args{'file'}
Aresult
11
00
18  
19 0 $self->{agentname} = "\$agent";
20  
21 0 return $self;
22 }
23  
24 0 ▶sub agentname { shift->_elem('agentname', @_); }
Subroutine agentname: not called CC=1 SCAR=6.9
Pod undocumented
25 0 ▶sub file { shift->_elem('file', @_); }
Subroutine file: not called CC=1 SCAR=6.9
Pod undocumented
26  
27 sub GetScript {
28 0 ▶ my $self = shift;
Subroutine GetScript: not called CC=2 SCAR=17.9
Pod undocumented
29  
30 0 ▶ if (open (SCRIPT, $self->{file})) {
Branch: 1 branch
BranchTrueFalseTotal
if (open SCRIPT, $self->{'file'}) { } 0 0 0
31 0 my @script = <SCRIPT>;
32 0 close SCRIPT;
33 0 return @script;
34 } else {
35 0 return undef;
36 }
37 }
38  
39 sub SetScript {
40 0 ▶ my $self = shift;
Subroutine SetScript: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my $script = shift;
42  
43 0 my $scriptfile = $self->{'file'};
44 0 open (SCRIPT, ">$scriptfile");
45 0 print SCRIPT $script;
46 0 close SCRIPT;
47 }
48  
49 sub Log {
50 0 ▶ my $self = shift;
Subroutine Log: not called CC=3 SCAR=24.8
Pod undocumented
51 0 my $function = shift;
52 0 ▶ my $args = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
53  
54 0 ▶ return unless $function;
Branch: 1 branch
BranchTrueFalseTotal
unless $function 0 0 0
55 0 my $line = $self->{agentname} . "->$function($args);\n";
56  
57 0 my $scriptfile = $self->{'file'};
58 0 open (SCRIPT, ">>$scriptfile");
59 0 print SCRIPT $line;
60 0 close SCRIPT;
61 }
62  
63 sub LogComment {
64 0 ▶ my $self = shift;
Subroutine LogComment: not called CC=1 SCAR=6.9
Pod undocumented
65 0 my $comment = shift;
66  
67 0 my $scriptfile = $self->{'file'};
68 0 open (SCRIPT, ">>$scriptfile");
69 0 print SCRIPT "# $comment\n";
70 0 close SCRIPT;
71 }
72  
73 sub LogLine {
74 0 ▶ my $self = shift;
Subroutine LogLine: not called CC=1 SCAR=6.9
Pod undocumented
75 0 my %args = (
76 line => "",
77 @_
78 );
79  
80 0 my $scriptfile = $self->{'file'};
81 0 open (SCRIPT, ">>$scriptfile");
82 0 print SCRIPT $args{line}, "\n";
83 0 close SCRIPT;
84 }
85  
86 sub GotoPage {
87 0 ▶ my $self = shift;
Subroutine GotoPage: not called CC=1 SCAR=6.9
Pod undocumented
88 0 my %args = (
89 url => "",
90 @_
91 );
92  
93 0 $self->Log("get", "'$args{url}'");
94 }
95  
96 sub FollowLink {
97 0 ▶ my $self = shift;
Subroutine FollowLink: not called CC=2 SCAR=17.9
Pod undocumented
98 0 my %args = (
99 text => "",
100 index => "",
101 @_
102 );
103  
104 0 ▶ if ($args{text}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'text'}) { } 0 0 0
105 0 $args{text} =~ s/"/\\"/g;
106 0 $self->Log("follow_link",
107 "text => '$args{text}', n => '$args{index}'");
108 } else {
109 0 $self->Log("follow_link",
110 "n => '$args{index}'");
111 }
112 }
113  
114 sub SetFieldsAndSubmit {
115 0 ▶ my $self = shift;
Subroutine SetFieldsAndSubmit: not called CC=3 SCAR=24.8
Pod undocumented
116 0 my %args = (
117 name => "",
118 number => undef,
119 fields => {},
120 button_name => {},
121 button_value => {},
122 button_number => {},
123 @_
124 );
125  
126 0 $self->SetForm(name => $args{name}, number => $args{number});
127  
128 0 my %fields = %{$args{'fields'}};
129 0 foreach my $field (keys %fields) {
130 0 ▶ if ($fields{$field}{'type'} eq 'checkbox') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fields{$field}{'type'} eq 'checkbox') { } 0 0 0
131 $self->Check(name => $fields{$field}{'name'},
132 0 value => $fields{$field}{'value'});
133 } else {
134 $self->SetField(name => $fields{$field}{'name'},
135 0 value => $fields{$field}{'value'});
136 }
137 }
138 # use click instead of submit
139 $self->Click(name => $args{name},
140 button_name => $args{button_name},
141 button_value => $args{button_value},
142 button_number => $args{button_number},
143 0 );
144 }
145  
146 sub SetForm {
147 0 ▶ my $self = shift;
Subroutine SetForm: not called CC=2 SCAR=17.9
Pod undocumented
148 0 my %args = (
149 @_
150 );
151  
152 0 ▶ if ($args{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'name'}) { } 0 0 0
153 0 $self->Log("form_name", "'$args{name}'");
154 } else {
155 0 $self->Log("form_number", $args{number});
156 }
157 }
158  
159 sub SetField {
160 0 ▶ my $self = shift;
Subroutine SetField: not called CC=2 SCAR=17.9
Pod undocumented
161 0 my %args = (
162 name => undef,
163 value => '',
164 @_
165 );
166  
167 0 ▶ return unless $args{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"name"} 0 0 0
168  
169 # escape single quotes
170 0 $args{name} =~ s/'/\\'/g;
171 0 $args{value} =~ s/'/\\'/g;
172  
173 0 $self->Log("field", "'$args{name}', '$args{value}'");
174 }
175  
176 sub Check {
177 0 ▶ my $self = shift;
Subroutine Check: not called CC=3 SCAR=24.8
Pod undocumented
178 0 my %args = (
179 name => undef,
180 value => undef,
181 @_
182 );
183  
184 0 ▶ return unless $args{name} && $args{value};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"name"} and $args{"value"} 0 0 0
Condition0%0/3
$args{"name"} and $args{"value"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"name"} and $args{"value"}
$args{"name"} $args{"value"}
Truth table0%0/3
A and B
A= $args{"name"}B= $args{"value"}
ABresult
0X0
100
111
185  
186 # escape single quotes
187 0 $args{name} =~ s/'/\\'/g;
188 0 $args{value} =~ s/'/\\'/g;
189  
190 0 $self->Log("tick", "'$args{name}', '$args{value}'");
191 }
192  
193 sub UnCheck {
194 0 ▶ my $self = shift;
Subroutine UnCheck: not called CC=3 SCAR=24.8
Pod undocumented
195 0 my %args = (
196 name => undef,
197 value => undef,
198 @_
199 );
200  
201 0 ▶ return unless $args{name} && $args{value};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"name"} and $args{"value"} 0 0 0
Condition0%0/3
$args{"name"} and $args{"value"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"name"} and $args{"value"}
$args{"name"} $args{"value"}
Truth table0%0/3
A and B
A= $args{"name"}B= $args{"value"}
ABresult
0X0
100
111
202  
203 # escape single quotes
204 0 $args{name} =~ s/'/\\'/g;
205 0 $args{value} =~ s/'/\\'/g;
206  
207 0 $self->Log("untick", "'$args{name}', '$args{value}'");
208 }
209  
210 sub Submit {
211 0 ▶ my $self = shift;
Subroutine Submit: not called CC=5 SCAR=34.0
Pod undocumented
212 0 my %args = (
213 @_
214 );
215  
216 0 my $submitargs = '';
217 0 ▶ if ($args{name}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'name'}) { } 0 0 0
elsif ($args{'number'}) { } 0 0 0
218 0 $submitargs = "form_name => '$args{name}', ";
219 } elsif ($args{number}) {
220 0 $submitargs = "form_number => '$args{number}'";
221 }
222  
223 0 ▶ $submitargs .= ', ' if $submitargs;
Branch: 1 branch
BranchTrueFalseTotal
if $submitargs 0 0 0
224  
225 0 ▶ if ($args{button_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"button_name"}) 0 0 0
226 0 $submitargs .= "button => $args{button_name}";
227 }
228  
229 # TODO: also support button value, number
230 # Don't add this until WWW::Mechanize supports it
231  
232 0 $self->Log("submit_form", $submitargs);
233 }
234  
235 sub Click {
236 0 ▶ my $self = shift;
Subroutine Click: not called CC=2 SCAR=17.9
Pod undocumented
237 0 my %args = (
238 @_
239 );
240
241 0 my $clickargs;
242 0 ▶ if ($args{button_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"button_name"}) 0 0 0
243 0 $clickargs = "'$args{button_name}'";
244 }
245  
246 # TODO: also support button value, number
247 # Don't add this until WWW::Mechanize supports it
248 0 $self->Log("click", $clickargs);
249 }
250  
251 2 1;
« Recorder.pm ↑ Summary