Card.pm

filter: Statementstmt 22.2% 28 / 126 Branchbran 5.5% 2 / 36 Conditioncond 8.3% 1 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 31.2% 5 / 16 Podpod 91.6% 11 / 12 totaltotal 22.3% 47 / 210 CC 24 SCAR 34.0
CC
24
Cov
18%
table
72.0
link_list
56.0
value_list
20.0
CRAP 30.1
↑ Summary Card/Palm.pm »
1 package WML::Card;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 $VERSION = '0.02';
8  
9 1 my $pt = [
10 { 'ua' => '7110', 'ot' => 'WML::Card::7110' },
11 { 'ua' => '7160', 'ot' => 'WML::Card::7110' },
12 { 'ua' => 'wapsilon', 'ot' => 'WML::Card::7110' },
13 { 'ua' => 'motorola', 'ot' => 'WML::Card::UP' },
14 { 'ua' => 'up', 'ot' => 'WML::Card::UP' },
15 { 'ua' => 'wapman', 'ot' => 'WML::Card::Palm' },
16 { 'ua' => 'ezwapbrowser', 'ot' => 'WML::Card::Palm' },
17 { 'ua' => 'nokia-wap-toolkit', 'ot' => 'WML::Card' },
18 ];
19  
20  
21 1 ▶sub guess {
Subroutine guess: called CC=4 SCAR=13.9
Pod documented
22 1 shift;
23 1 my $id = shift;
24 1 my $title =shift;
25 1 ▶ my $ua = shift || $ENV{'HTTP_USER_AGENT'};
Condition33%1/3
shift() || $ENV{'HTTP_USER_AGENT'}
l!l&&r!l&&!r
100
MC/DC0%0/2
shift() || $ENV{'HTTP_USER_AGENT'}
shift() $ENV{'HTTP_USER_AGENT'}
Truth table33%1/3
A || B
A= shift()B= $ENV{'HTTP_USER_AGENT'}
ABresult
1X1
011
000
26 1 my $ot = 'WML::Card';
27 1 for my $p (@$pt) {
28 5 ▶ if ($ua =~ /$p->{'ua'}/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ua =~ /$p->{"ua"}/i) 1 4 5
29 1 $ot = $p->{'ot'};
30 1 last;
31 }
32 }
33 1 eval "require $ot";
34
35 # if ($@) { ...
36 # } else { ...
37 # }
38  
39 1 my $ob = new $ot($id, $title);
40 1 return $ob;
41 }
42  
43 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
44 1 my $cl = shift;
45 1 my ($_id, $_title) = @_;
46 1 my $hr = {
47 '_id' => $_id,
48 '_title' => $_title,
49 '_do'=> undef,
50 '_body'=> undef,
51 '_next'=> 'Ver más',
52 };
53 1 return bless $hr, $cl;
54 }
55  
56  
57 0 ▶sub buttons{
Subroutine buttons: not called CC=2 SCAR=17.9
Pod documented
58 0 my $self =shift;
59 0 my ($label, $type, $task, $href) = @_;
60 0 $self->{'_do'} .= << "EOF";
61 <do type="$type" label="$label">
62 EOF
63  
64 0 ▶ $self->{'_do'} .= $task eq 'prev' ? '<prev/>' : "<go href=\"$href\"/>";
Branch: 1 branch
BranchTrueFalseTotal
$task eq 'prev' ? : 0 0 0
65 0 $self->{'_do'} .= '</do>';
66 }
67  
68 0 ▶sub table{
Subroutine table: not called CC=8 SCAR=42.8
Pod documented
69 0 my $self = shift;
70 0 my ($data, $title, $offset, $pager, @headers) = @_;
71 0 my $texto;
72 my $i;
73 0 my $total = scalar @{$data};
74
75 0 $self->{'_body'}.= "<p align='center'>$title";
76 0 $self->{'_body'}.= "<table columns='3'>";
77
78 #Header
79 0 ▶ if (scalar @headers) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @headers) 0 0 0
80 0 $self->{'_body'}.= '<tr><td>&nbsp;</td>';
81 0 ▶ for ($i=0; $i < 2; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 2) 0 0 0
82 0 $self->{'_body'}.= '<td>';
83 0 $texto = $self->_format_text($headers[$i]);
84 0 $self->{'_body'}.= "$texto</td>";
85 }
86 0 $self->{'_body'}.= '</tr>';
87 }
88  
89 #Datos
90 0 ▶ for ($i=($offset * $pager); (($i < ($offset * $pager + $pager)) && ($i < $total));$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $offset * $pager + $pager and $i < $total) 0 0 0
Condition0%0/3
$i < $offset * $pager + $pager and $i < $total
!ll&&!rl&&r
000
MC/DC0%0/2
$i < $offset * $pager + $pager and $i < $total
$i < $offset * $pager + $pager $i < $total
Truth table0%0/3
A and B
A= $i < $offset * $pager + $pagerB= $i < $total
ABresult
0X0
100
111
91 0 $self->{'_body'}.= "<tr><td>&nbsp;</td>";
92 0 ▶ for (my $j; $j < 2 ; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < 2) 0 0 0
93 0 $self->{'_body'}.= "<td>";
94 0 $texto = $self->_format_text($data->[$i][$j]);
95 0 $self->{'_body'}.= "$texto</td>";
96 }
97 0 $self->{'_body'}.= '</tr>';
98 }
99 0 $self->{'_body'}.= "</table></p>";
100 0 $offset++;
101
102 0 ▶ if ($i < $total){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $total) 0 0 0
103 0 my $next =$self->_format_text($self->{'_next'});
104 0 $ENV{'QUERY_STRING'} =~ s/^(o=\d[&]?)//;
105 0 ▶ my $href = length $ENV{'QUERY_STRING'}> 0 ? "?o=$offset&$ENV{'QUERY_STRING'}" : "?o=$offset";
Branch: 1 branch
BranchTrueFalseTotal
length $ENV{'QUERY_STRING'} > 0 ? : 0 0 0
106 0 $href =~ s/\&/\&amp;/gs;
107 0 $self->{'_body'}.= << "EOF";
108 <p><a href=\"$href\">$next</a></p>
109 EOF
110 }
111 }
112  
113 0 ▶sub link_list{
Subroutine link_list: not called CC=7 SCAR=40.3
Pod documented
114 0 my $self = shift;
115 0 my ($name, $listtitle, $offset, $pager, $data, $align) = @_;
116 0 ▶ $align = defined $align ? $align : 'left';
Branch: 1 branch
BranchTrueFalseTotal
defined $align ? : 0 0 0
117 0 $self->{'_body'}.= "<p align=\"$align\">";
118 0 ▶ $self->{'_body'}.= sprintf ("%s", $self->_format_text($listtitle)) if defined $listtitle;
Branch: 1 branch
BranchTrueFalseTotal
if defined $listtitle 0 0 0
119 0 $name = $self->_format_text($name);
120 0 $self->{'_body'}.= "<select ivalue=\"0\" name=\"$name\">\n";
121  
122 0 my $total = scalar @{$data};
123 0 my $i;
124 0 ▶ for ($i= ($offset * $pager);
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $offset * $pager + $pager and $i < scalar @{$data;}) 0 0 0
Condition0%0/3
$i < $offset * $pager + $pager and $i < scalar @{$data;}
!ll&&!rl&&r
000
MC/DC0%0/2
$i < $offset * $pager + $pager and $i < scalar @{$data;}
$i < $offset * $pager + $pager $i < scalar @{$data;}
Truth table0%0/3
A and B
A= $i < $offset * $pager + $pagerB= $i < scalar @{$data;}
ABresult
0X0
100
111
125 0 ($i < ($offset * $pager + $pager) && ($i < scalar @{$data}));
126 $i++) {
127 0 my $opt = $self->_format_text($data->[$i][$0]);
128 0 $self->{'_body'}.= "<option onpick=\"$data->[$i][1]\">$opt</option>\n";
129 }
130 0 $offset++;
131 0 ▶ if ($i < $total){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $total) 0 0 0
132 0 my $next =$self->_format_text($self->{'_next'});
133 0 $ENV{'QUERY_STRING'} =~ s/^(o=\d[&]?)//;
134 0 ▶ my $href = length $ENV{'QUERY_STRING'}> 0 ? "?o=$offset&$ENV{'QUERY_STRING'}" : "?o=$offset";
Branch: 1 branch
BranchTrueFalseTotal
length $ENV{'QUERY_STRING'} > 0 ? : 0 0 0
135 0 $href =~ s/\&/\&amp;/gs;
136 0 $self->{'_body'}.= << "EOF";
137 <option onpick=\"$href\">$next</option>
138 EOF
139 }
140  
141 0 $self->{'_body'}.= << 'EOF';
142 </select>
143 </p>
144 EOF
145 };
146  
147  
148 0 ▶sub value_list{
Subroutine value_list: not called CC=4 SCAR=30.0
Pod documented
149 0 my $self = shift;
150 0 my ($name, $listtitle, $offset,$pager,$data) = @_;
151 0 $self->{'_body'}.= '<p mode="nowrap">';
152 0 ▶ $self->{'_body'}.= sprintf ("%s", $self->_format_text($listtitle)) if defined $listtitle;
Branch: 1 branch
BranchTrueFalseTotal
if defined $listtitle 0 0 0
153 0 $name = $self->_format_text($name);
154 0 $self->{'_body'}.= "<select ivalue=\"0\" name=\"$name\">\n";
155  
156 0 my $total = scalar @{$data};
157 0 ▶ for (my $i= ($offset * $pager);
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $offset * $pager + $pager and $i < $total) 0 0 0
Condition0%0/3
$i < $offset * $pager + $pager and $i < $total
!ll&&!rl&&r
000
MC/DC0%0/2
$i < $offset * $pager + $pager and $i < $total
$i < $offset * $pager + $pager $i < $total
Truth table0%0/3
A and B
A= $i < $offset * $pager + $pagerB= $i < $total
ABresult
0X0
100
111
158 ($i < ($offset * $pager + $pager) && ($i < $total));
159 $i++) {
160 0 my $opt = $self->_format_text($data->[$i][$0]);
161 0 $self->{'_body'}.= "<option value=\"$data->[$i][1]\">$opt</option>\n";
162 }
163 0 $self->{'_body'}.= << "EOF";
164 </select>
165 </p>
166 EOF
167 };
168  
169 0 ▶sub print{
Subroutine print: not called CC=1 SCAR=6.9
Pod documented
170 0 my $self = shift;
171 0 $self->{'_title'} = $self->_format_text($self->{'_title'});
172 0 print << "EOF";
173 <card id="$self->{'_id'}" title="$self->{'_title'}">
174 $self->{'_do'}
175 $self->{'_body'}
176 </card>
177 EOF
178 };
179  
180 0 ▶sub info{
Subroutine info: not called CC=1 SCAR=6.9
Pod documented
181 0 my $self = shift;
182 0 my $content = shift;
183 0 $content = $self->_format_text($content);
184 0 $content =~ s/\n/<br\/>\n/gs;
185 0 $content = "<p>$content</p>";
186 0 $content =~ s/<br\/>\n<\/p>/<\/p>/;
187 0 $self->{'_body'} .= $content;
188 };
189  
190 0 ▶sub img{
Subroutine img: not called CC=1 SCAR=6.9
Pod documented
191 0 my $self = shift;
192 0 my ($file, $alt) = @_;
193 0 $self->{'_body'} .= << "EOF";
194 <p align="left">
195 <img src="$file" alt = "$alt"/>
196 </p>
197 EOF
198 }
199  
200 0 ▶sub input{
Subroutine input: not called CC=4 SCAR=30.0
Pod documented
201 0 my $self = shift;
202 0 my ($label, $text, $name, $format, $type, $size, $target, $arg) = @_;
203 0 ▶ $target = defined $arg ? "$target?$arg&amp;$name=\$($name)" : "$target?$name=\$($name)";
Branch: 1 branch
BranchTrueFalseTotal
defined $arg ? : 0 0 0
204 0 ▶ $format = " format=\"$size$format\"" if defined $format;
Branch: 1 branch
BranchTrueFalseTotal
if defined $format 0 0 0
205 0 ▶ $size = " size=\"$size\"" if defined $size ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $size 0 0 0
206 0 $self->{'_body'} .= << "EOF";
207 <do type="accept" label="$label">
208 <go href="$target"/>
209 </do>
210 <p align="center" mode="wrap">
211 $text
212 <input type="$type" name="$name" title="$name" $format $size/>
213 <a href="$target">$label</a>
214 </p>
215 EOF
216 }
217  
218 0 ▶sub link{
Subroutine link: not called CC=1 SCAR=6.9
Pod documented
219 0 my $self = shift;
220 0 my ($target, $text) = @_;
221 0 $self->{'_body'} .= << "EOF";
222 <p><a href="$target">$text</a></p>
223 EOF
224 }
225  
226  
227 0 ▶sub br{
Subroutine br: not called CC=1 SCAR=6.9
Pod documented
228 0 my $self = shift;
229 0 $self->{'_body'} .= '<br/>';
230 }
231  
232 0 ▶sub _format_text {
Subroutine _format_text: not called CC=1 SCAR=6.9
233 0 my $self = shift;
234 0 my $txt = shift;
235 0 $txt =~ s/([^\w\s])/sprintf '&#%03d;', ord($1)/eg;
236 0 $txt =~ s/\r//g;
237 0 $txt;
238 }
239  
240  
241 1 1;
242  
243 =head1 NAME
244  
245 WML::Card - Perl extension for builiding WML Cards according to the browser being used.
246  
247 =head1 SYNOPSIS
248  
249 use WML::Card;
250  
251 my $options= [
252 ['Option 1', 'http://...'],
253 ['Option 2', 'http://...'],
254 ];
255  
256 my $c = WML::Card->guess('index','Wap Site');
257 $c->link_list('indice', undef, 0, $options, $options);
258 $c->print;
259  
260 =head1 DESCRIPTION
261  
262 This perl library simplifies the creation of WML cards on the fly. It produces
263 the most suitable wml code for the browser requesting the card. In this way the
264 one building the cards does not have to worry about the differences in how each
265 wap browser displays the wml code. In combination wht WML::Deck it provides
266 functionality to build WAP applications.
267  
268 =head2 Methods
269  
270 =over 4
271  
272 =item $card = WML::Card->guess( $id, $title, [$user_agent] );
273  
274 This class method constructs a new WML::Card object. The first argument defines
275 the WML card's id and the second argument its title. The if the third argument is
276 not defined, the value is obtained from $ENV{'HTTP_USER_AGENT'}.
277  
278  
279 =item $c->buttons($label, $type, $task, $href)
280  
281  
282 =item $c->table ($data, $title, $offset, $pager, @headers)
283  
284 =item $c->link_list($name, $listtitle, $offset, $pager, $data, $align)
285  
286 =item $c->value_list($name, $listtitle, $offset,$pager,$data)
287  
288 The variable $data is an array reference like:
289 my $menu_items= [
290 ['Option 1', 'http://...'],
291 ['Option 2', 'http://...'],
292 ];
293  
294 The variable $pager is the number of items wanted to be displayed in each card.
295  
296 =item $c->print
297  
298 =item $c->info($content)
299  
300 =item $c->img($file, $alt)
301  
302 =item $c->input($label, $text, $name, $format, $type, $size, $target, $arg);
303  
304 =item $c->link($target, $text);
305  
306 =item $c->br
307  
308 =head1 AUTHOR
309  
310 Mariana Alvaro mariana@alvaro.com.ar
311  
312 Copyright 2000 Mariana Alvaro. All rights reserved.
313 This library is free software; you can redistribute it and/or
314 modify it under the same terms as Perl itself.
315  
316 =head1 SEE ALSO
317  
318 WML::Deck
319  
320 =cut
↑ Summary Card/Palm.pm »