Plugin/HTML/AttributeInfo.pm

filter: Statementstmt 14.5% 19 / 131 Branchbran 0.0% 0 / 80 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 29.4% 5 / 17 Podpod n/a totaltotal 10.0% 24 / 238 CC 53 SCAR 48.2
CC
53
Cov
9%
_make_response_message
342.0
_command_is_deprecated
132.0
_command_comment
42.0
CRAP 123.4
↑ Summary Plugin/Google/PageRank.pm »
1 package POE::Component::IRC::Plugin::HTML::AttributeInfo;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '2.001004'; # VERSION
7  
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use base qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
11 POE::Component::IRC::Plugin::BaseWrap
12 POE::Component::IRC::Plugin::HTML::AttributeInfo::Data
13 1 );
14  
15 1 my @Attrs = __PACKAGE__->_data();
16 1 my %Valid_Attrs = __PACKAGE__->_valid_attrs();
17  
18  
19 0 ▶sub _make_default_args {
Subroutine _make_default_args: not called CC=1 SCAR=6.9
20 return (
21 0 trigger => qr/^attr\s+(?=\S+)/i,
22 response_event => 'irc_html_attribute',
23 line_length => 350,
24 cmdtriggers => {
25 list_attr =>
26 qr/^ l (?:ist)? \s* a (?:ttr (?:ibute s? )? )? \s+ (?=\S+) /xi,
27  
28 list_el =>
29 qr/^ l (?:ist)? \s* e (?:l (?:ement s?)? )? \s+ (?=\S+) /xi,
30  
31 type => qr/^ t (?: ype )? \s+ (?=\S+) /xi,
32  
33 default
34 => qr/^ d (?: efault )? (?: \s+ value s? )? \s+ (?=\S+) /xi,
35  
36 deprecated => qr/^ de (?: precated )? \s+ (?=\S+) /xi,
37  
38 dtd => qr/^ dtd \s+ (?=\S+) /xi,
39  
40 comment => qr/^ c (?:omment s?)? \s+ (?=\S+) /xi,
41  
42 total => qr/^ to (?:tal)? /xi,
43 },
44 );
45 }
46  
47 0 ▶sub _message_into_response_event { 'out' }
Subroutine _message_into_response_event: not called CC=1 SCAR=6.9
48  
49 0 ▶sub _make_response_message {
Subroutine _make_response_message: not called CC=18 SCAR=58.3
50 0 my ( $self, $in_ref ) = @_;
51  
52 0 my $in = lc $in_ref->{what};
53  
54 $self->{debug}
55 0 ▶ and carp "AttrInfo: input: `$in`";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp("AttrInfo: input: `$in`") 0 0 0
56  
57 0 my $trig_ref = $self->{cmdtriggers};
58  
59 0 ▶ if ( $in =~ s/$trig_ref->{list_attr}// ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($in =~ s/$trig_ref->{'list_attr'}//) { } 0 0 0
elsif ($in =~ s/$trig_ref->{'list_el'}//) { } 0 0 0
elsif ($in =~ s/$trig_ref->{'type'}//) { } 0 0 0
elsif ($in =~ s/$trig_ref->{'default'}//) { } 0 0 0
elsif ($in =~ s/$trig_ref->{'deprecated'}//) { } 0 0 0
elsif ($in =~ s/$trig_ref->{'comment'}//) { } 0 0 0
elsif ($in =~ s/$trig_ref->{'dtd'}//) { } 0 0 0
elsif ($in =~ s/$trig_ref->{'total'}//) { } 0 0 0
60 $self->{debug}
61 0 ▶ and carp "Attr LIST ATTRIBUTES ($in)";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp("Attr LIST ATTRIBUTES ($in)") 0 0 0
62  
63 0 return $self->_prepare_output(
64 $self->_command_get_attrs_for_el( uc $in )
65 );
66 }
67 elsif ( $in =~ s/$trig_ref->{list_el}// ) {
68 $self->{debug}
69 0 ▶ and carp "Attr LIST ELEMENTS ($in)";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp("Attr LIST ELEMENTS ($in)") 0 0 0
70  
71 0 return $self->_prepare_output(
72 $self->_command_get_elements_for_attr( $in )
73 );
74 }
75 elsif ( $in =~ s/$trig_ref->{type}// ) {
76 $self->{debug}
77 0 ▶ and carp "Attr TYPE ($in)";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp("Attr TYPE ($in)") 0 0 0
78  
79 0 return $self->_prepare_output( $self->_command_attr_type( $in ) );
80 }
81 elsif ( $in =~ s/$trig_ref->{default}// ) {
82 $self->{debug}
83 0 ▶ and carp "Attr DEFAULT VALUE ($in)";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp("Attr DEFAULT VALUE ($in)") 0 0 0
84  
85 0 return $self->_prepare_output(
86 $self->_command_default_value( $in )
87 );
88 }
89 elsif ( $in =~ s/$trig_ref->{deprecated}// ) {
90 $self->{debug}
91 0 ▶ and carp "Attr DEPRECATED ($in)";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp("Attr DEPRECATED ($in)") 0 0 0
92  
93 0 return $self->_prepare_output(
94 $self->_command_is_deprecated( $in )
95 );
96 }
97 elsif ( $in =~ s/$trig_ref->{comment}// ) {
98 $self->{debug}
99 0 ▶ and carp "Attr COMMENT ($in)";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp("Attr COMMENT ($in)") 0 0 0
100  
101 0 return $self->_prepare_output( $self->_command_comment( $in ) );
102 }
103 elsif ( $in =~ s/$trig_ref->{dtd}// ) {
104 $self->{debug}
105 0 ▶ and carp "Attr DTD ($in)";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp("Attr DTD ($in)") 0 0 0
106  
107 0 return $self->_prepare_output( $self->_command_dtd( $in ) );
108 }
109 elsif ( $in =~ s/$trig_ref->{total}// ) {
110 $self->{debug}
111 0 ▶ and carp "Attr TOTAL ($in)";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"debug"} and carp("Attr TOTAL ($in)") 0 0 0
112  
113 0 return $self->_prepare_output( $self->_command_total );
114 }
115  
116 0 return [ "Invalid command in HTML Attributes plugin" ];
117 }
118  
119 0 ▶sub _command_total {
Subroutine _command_total: not called CC=1 SCAR=6.9
120 0 return "I know of " . keys( %Valid_Attrs ) . " attributes in total";
121 }
122  
123 0 ▶sub _command_comment {
Subroutine _command_comment: not called CC=6 SCAR=37.4
124 0 my ( $self, $attr ) = @_;
125  
126 return "Attribute $attr is not in my database"
127 0 ▶ unless exists $Valid_Attrs{ $attr };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Valid_Attrs{$attr} 0 0 0
128  
129 0 my %comments;
130 0 for ( @Attrs ) {
131 0 ▶ if ( $_->{name} eq $attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"name"} eq $attr) 0 0 0
132 0 push @{ $comments{ $_->{comment} } },
133 0 @{ $_->{related_elements} };
134 }
135 }
136  
137 0 ▶ keys %comments
Branch: 1 branch
BranchTrueFalseTotal
keys %comments or return "I don't have any comments regarding $attr attribute" 0 0 0
138 or return "I don't have any comments regarding $attr attribute";
139  
140 0 ▶ if ( keys %comments == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %comments == 1) { } 0 0 0
141 0 return "Comment for $attr is: " . (keys %comments)[0];
142 }
143 else {
144 return "Attribute $attr has the following comments: "
145 . join q|; |,
146 0 map { "$_: [ " . join( q|, |, @{ $comments{ $_ } } ) . " ]" }
147 sort keys %comments;
148 }
149 }
150  
151 0 ▶sub _command_dtd {
Subroutine _command_dtd: not called CC=4 SCAR=30.0
152 0 my ( $self, $attr ) = @_;
153 0 $attr =~ s/\s+//g;
154  
155 return "Attribute $attr is not in my database"
156 0 ▶ unless exists $Valid_Attrs{ $attr };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Valid_Attrs{$attr} 0 0 0
157  
158 0 my %dtds;
159 0 for ( @Attrs ) {
160 0 ▶ if ( $_->{name} eq $attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"name"} eq $attr) 0 0 0
161 0 $dtds{ $_->{dtd} } = 1;
162 }
163 }
164  
165 0 return "Attribute $attr appears in DTD: "
166 . join q|, |, sort keys %dtds;
167 }
168  
169 0 ▶sub _command_is_deprecated {
Subroutine _command_is_deprecated: not called CC=11 SCAR=48.8
170 0 my ( $self, $attr ) = @_;
171 0 $attr =~ s/\s+//g;
172  
173 return "Attribute $attr is not in my database"
174 0 ▶ unless exists $Valid_Attrs{ $attr };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Valid_Attrs{$attr} 0 0 0
175  
176 0 my ( %deprecated_els, %not_deprecated_els );
177 0 for ( @Attrs ) {
178 next
179 0 ▶ unless $_->{name} eq $attr;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->{"name"} eq $attr 0 0 0
180  
181 0 ▶ if ( $_->{deprecated} eq 'deprecated' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{'deprecated'} eq 'deprecated') { } 0 0 0
182 $deprecated_els{ $_ } = 1
183 0 for @{ $_->{related_elements} };
184 }
185 else {
186 $not_deprecated_els{ $_ } = 1
187 0 for @{ $_->{related_elements} };
188 }
189 }
190  
191 0 ▶ if ( keys %not_deprecated_els and not keys %deprecated_els ) {
Branch: 2 branches
BranchTrueFalseTotal
if (keys %not_deprecated_els and not keys %deprecated_els) { } 0 0 0
elsif (keys %deprecated_els and not keys %not_deprecated_els) { } 0 0 0
Condition0%0/3
keys %not_deprecated_els and not keys %deprecated_els
!ll&&!rl&&r
000
MC/DC0%0/2
keys %not_deprecated_els and not keys %deprecated_els
keys %not_deprecated_els not keys %deprecated_els
Truth table0%0/3
A and not(B)
A= keys %not_deprecated_elsB= not keys %deprecated_els
ABresult
0X0
100
111
192 0 return "Attribute $attr is NOT deprecated";
193 }
194 ▶ elsif ( keys %deprecated_els and not keys %not_deprecated_els ) {
Condition0%0/3
keys %deprecated_els and not keys %not_deprecated_els
!ll&&!rl&&r
000
MC/DC0%0/2
keys %deprecated_els and not keys %not_deprecated_els
keys %deprecated_els not keys %not_deprecated_els
Truth table0%0/3
A and not(B)
A= keys %deprecated_elsB= not keys %not_deprecated_els
ABresult
0X0
100
111
195 0 return "Attribute $attr is deprecated";
196 }
197 else {
198 0 return "Attribute $attr is deprecated on element(s): "
199 . join( q|, |, sort keys %deprecated_els )
200 . " and NOT deprecated on element(s): "
201 . join q|, |, sort keys %not_deprecated_els;
202 }
203 }
204  
205 0 ▶sub _command_default_value {
Subroutine _command_default_value: not called CC=5 SCAR=34.0
206 0 my ( $self, $attr ) = @_;
207 0 $attr =~ s/\s+//g;
208  
209 return "Attribute $attr is not in my database"
210 0 ▶ unless exists $Valid_Attrs{ $attr };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Valid_Attrs{$attr} 0 0 0
211  
212 0 my %vals;
213 0 for ( @Attrs ) {
214 0 ▶ if ( $_->{name} eq $attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"name"} eq $attr) 0 0 0
215 0 push @{ $vals{ $_->{default_value} } },
216 0 @{ $_->{related_elements} };
217 }
218 }
219  
220 0 ▶ if ( keys %vals == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %vals == 1) { } 0 0 0
221 0 return "Attribute $attr\'s default value is " . (%vals)[0];
222 }
223 else {
224 return "Attribute $attr\'s default values are: " .
225 join q|; |,
226 0 map { "$_ [ " . join( q|, |, @{ $vals{ $_ } } ) . " ]" }
227 sort keys %vals;
228 }
229 }
230  
231 0 ▶sub _command_attr_type {
Subroutine _command_attr_type: not called CC=4 SCAR=30.0
232 0 my ( $self, $attr ) = @_;
233 0 $attr =~ s/\s+//g;
234  
235 return "Attribute $attr is not in my database"
236 0 ▶ unless exists $Valid_Attrs{ $attr };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Valid_Attrs{$attr} 0 0 0
237  
238  
239 0 my %types;
240 0 for ( @Attrs ) {
241 0 ▶ if ( $_->{name} eq $attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"name"} eq $attr) 0 0 0
242 0 $types{ $_->{type} } = 1;
243 }
244 }
245  
246 0 return "Attribute $attr\'s value is of type: "
247 . join q|, |, sort keys %types;
248 }
249  
250 0 ▶sub _command_get_elements_for_attr {
Subroutine _command_get_elements_for_attr: not called CC=5 SCAR=34.0
251 0 my ( $self, $attr ) = @_;
252 0 $attr =~ s/\s+//g;
253  
254 return "Attribute $attr is not in my database"
255 0 ▶ unless exists $Valid_Attrs{ $attr };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Valid_Attrs{$attr} 0 0 0
256  
257 0 my %els;
258 0 for ( @Attrs ) {
259 next
260 0 ▶ unless $_->{name} eq $attr;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->{"name"} eq $attr 0 0 0
261  
262 0 my @attr_els = @{ $_->{related_elements} };
263 0 @els{ @attr_els } = (1) x @attr_els;
264 }
265  
266 0 ▶ return "Attribute $attr does not seem to apply to any elements"
Branch: 1 branch
BranchTrueFalseTotal
unless keys %els 0 0 0
267 unless keys %els;
268  
269 0 return "Attribute $attr applies to elements: "
270 . join q|, |, sort keys %els;
271 }
272  
273 0 ▶sub _command_get_attrs_for_el {
Subroutine _command_get_attrs_for_el: not called CC=5 SCAR=34.0
274 0 my ( $self, $el ) = @_;
275 0 $el =~ s/\s+//g;
276  
277 0 my %attrs;
278 0 for my $bit ( @Attrs ) {
279 0 for ( @{ $bit->{related_elements} } ) {
280 0 ▶ $attrs{ $bit->{name} } = 1
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $el 0 0 0
281 if $_ eq $el;
282 }
283 }
284  
285 0 ▶ return "Element $el does not have any attributes"
Branch: 1 branch
BranchTrueFalseTotal
unless keys %attrs 0 0 0
286 unless keys %attrs;
287  
288 0 return "Element $el has the following attributes: "
289 . join q|, |, sort keys %attrs;
290 }
291  
292 0 ▶sub _prepare_output {
Subroutine _prepare_output: not called CC=3 SCAR=24.8
293 0 my ( $self, $out ) = @_;
294 return
295 0 ▶ unless defined $out;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out 0 0 0
296  
297 0 my @out;
298 0 my $length = $self->{line_length};
299 0 ▶ while ( length $out > $length ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $out > $length) 0 0 0
300 0 push @out, substr $out, 0, $length;
301 0 $out = substr $out, $length;
302 }
303 0 return [ @out, $out ];
304 }
305  
306 1 1;
307 __END__
↑ Summary Plugin/Google/PageRank.pm »