Plugin/Attrs.pm

filter: Statementstmt 96.8% 31 / 32 Branchbran 60.0% 6 / 10 Conditioncond 72.7% 8 / 11 MC/DCmcdc 57.1% 4 / 7 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 84.2% 59 / 70 CC 13 SCAR 23.4
CC
13
Cov
85%
attrs
14.7
BEGIN
1.0
BEGIN
1.0
CRAP 10.4
« Plugin/Radio.pm ↑ Summary Factory.pm »
1 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package HTML::Widget::Plugin::Attrs;
4 # ABSTRACT: an HTML attribute string
5 15 $HTML::Widget::Plugin::Attrs::VERSION = '0.204';
6 15 ▶use parent 'HTML::Widget::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #pod =head1 DESCRIPTION
9 #pod
10 #pod This plugin produces HTML attribute strings.
11 #pod
12 #pod =cut
13  
14 15 ▶use HTML::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #pod =head1 METHODS
17 #pod
18 #pod =head2 C< provided_widgets >
19 #pod
20 #pod This plugin provides the following widgets: attrs
21 #pod
22 #pod =cut
23  
24 19 ▶sub provided_widgets { qw(attrs) }
Subroutine provided_widgets: called CC=1 SCAR=0.0
Pod documented
25  
26 #pod =head2 C< attrs >
27 #pod
28 #pod This method returns HTML attribute strings, so:
29 #pod
30 #pod $factory->attrs({
31 #pod size => 10,
32 #pod name => q(Michael "Five-Toes" O'Gambini),
33 #pod });
34 #pod
35 #pod will produce something like:
36 #pod
37 #pod size="10" name="Michael &quot;Five-Toes&quot;"
38 #pod
39 #pod None of the standard argument rewriting applies. These are the valid
40 #pod arguments:
41 #pod
42 #pod =over
43 #pod
44 #pod =item -tag
45 #pod
46 #pod This may be the name of an HTML element. If given, it will be used to look up
47 #pod what attributes are boolean.
48 #pod
49 #pod =item -bool
50 #pod
51 #pod This may be an arrayref of attribute names to treat as boolean arguments.
52 #pod
53 #pod =back
54 #pod
55 #pod All attributes not beginning with a dash will be treated as attributes for the
56 #pod attribute string. Boolean attributes will always have the attribute name as
57 #pod the value if true, and will be omitted if false.
58 #pod
59 #pod If both C<-tag> and C<-bool> are given, they are unioned.
60 #pod
61 #pod =cut
62  
63 # Note that we're totally replacing the standard args rewriting! This is not
64 # going to act quite like existing widget plugins! -- rjbs, 2008-05-05
65 # ALL unless they are boolean args.
66 1 ▶sub rewrite_arg { return $_[1] }
Subroutine rewrite_arg: called CC=1 SCAR=0.0
Pod documented
67  
68 1 ▶sub attrs {
Subroutine attrs: called CC=13 SCAR=26.9
Pod documented
69 1 my ($self, $factor, $arg) = @_;
70  
71 1 my $attr = {};
72  
73 1 my %bool;
74 1 ▶ $bool{lc $_} = 1 for @{ $arg->{-bool} || [] };
Condition50%1/2
$arg->{'-bool'} || []
l!l
10
MC/DC0%0/1
$arg->{'-bool'} || []
$arg->{'-bool'}
Truth table50%1/2
A
A= $arg->{'-bool'}
Aresult
11
00
75  
76 1 require HTML::Tagset;
77 1 ▶ if ($arg->{-tag} and my $entry = $HTML::Tagset::boolean_attr{$arg->{-tag}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{"-tag"} and my $entry = $HTML::Tagset::boolean_attr{$arg->{"-tag"}}) 0 1 1
Condition33%1/3
$arg->{"-tag"} and my $entry = $HTML::Tagset::boolean_attr{$arg->{"-tag"}}
!ll&&!rl&&r
100
MC/DC0%0/2
$arg->{"-tag"} and my $entry = $HTML::Tagset::boolean_attr{$arg->{"-tag"}}
$arg->{"-tag"} my $entry = $HTML::Tagset::boolean_attr{$arg->{"-tag"}}
Truth table33%1/3
A and B
A= $arg->{"-tag"}B= my $entry = $HTML::Tagset::boolean_attr{$arg->{"-tag"}}
ABresult
0X0
100
111
78 0 ▶ $bool{lc $_} = 1 for (ref $entry ? keys %$entry : $entry);
Branch: 1 branch
BranchTrueFalseTotal
ref $entry ? : 0 0 0
79 }
80  
81 1 my $str = '';
82 1 ▶ for my $key (sort grep { $_ !~ /^-/ and defined $arg->{$_} } keys %$arg) {
Condition100%3/3
!($_ =~ /^-/) && defined $arg->{$_}
!ll&&!rl&&r
116
MC/DC100%2/2
!($_ =~ /^-/) && defined $arg->{$_}
!($_ =~ /^-/) defined $arg->{$_}
Truth table100%3/3
not(A) && B
A= !($_ =~ /^-/)B= defined $arg->{$_}
ABresult
0X0
100
111
83 6 my $is_bool = $bool{ lc $key };
84 6 ▶ next if $is_bool and not $arg->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $is_bool and not $arg->{$key} 1 5 6
Condition100%3/3
$is_bool and not $arg->{$key}
!ll&&!rl&&r
411
MC/DC100%2/2
$is_bool and not $arg->{$key}
$is_bool not $arg->{$key}
Truth table100%3/3
A and not(B)
A= $is_boolB= not $arg->{$key}
ABresult
0X0
100
111
85  
86 $str .= HTML::Entities::encode_entities($key)
87 . '="'
88 . ($is_bool ? HTML::Entities::encode_entities($key)
89 5 ▶ : HTML::Entities::encode_entities($arg->{$key}))
Branch: 1 branch
BranchTrueFalseTotal
$is_bool ? : 1 4 5
90 . '" ';
91 }
92  
93 # Remove the trailing space that we're sure to have -- rjbs, 2008-05-05
94 1 ▶ substr $str, -1, 1, '' if length $str;
Branch: 1 branch
BranchTrueFalseTotal
if length $str 1 0 1
95  
96 1 return $str;
97 }
98  
99 15 1;
100  
101 __END__
« Plugin/Radio.pm ↑ Summary Factory.pm »