Plugin/WWW/Lipsum.pm

filter: Statementstmt 21.8% 14 / 64 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 44.4% 4 / 9 Podpod n/a totaltotal 17.1% 18 / 105 CC 14 SCAR 32.3
CC
14
Cov
15%
_make_response_message
42.0
_make_poco_call
42.0
_make_poco
12.0
CRAP 25.4
« Plugin/Validator/CSS.pm ↑ Summary Plugin/CSS/SelectorTools.pm »
1 package POE::Component::IRC::Plugin::WWW::Lipsum;
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 base 'POE::Component::IRC::Plugin::BasePoCoWrap';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use POE::Component::WWW::Lipsum;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub _make_default_args {
Subroutine _make_default_args: not called CC=1 SCAR=6.9
12 return (
13 0 response_event => 'irc_lipsum',
14 trigger => qr/^lipsum\s*/i,
15 line_lengths => {
16 public => 350,
17 notice => 350,
18 privmsg => 350,
19 },
20 max_lines => {
21 public => 1,
22 notice => 5,
23 privmsg => 5,
24 },
25 );
26 }
27  
28 0 ▶sub _make_poco {
Subroutine _make_poco: not called CC=3 SCAR=24.8
29 0 my $self = shift;
30  
31 0 ▶ if ( not ref $self->{max_lines} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $self->{'max_lines'}) { } 0 0 0
32 $self->{max_lines} = {
33 public => $self->{max_lines},
34 notice => $self->{max_lines},
35 privmsg => $self->{max_lines},
36 0 };
37 }
38 else {
39 $self->{max_lines} = {
40 public => 1,
41 notice => 5,
42 privmsg => 5,
43 0 %{ $self->{max_lines} },
44 };
45 }
46  
47 0 ▶ if ( not ref $self->{line_lengths} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $self->{'line_lengths'}) { } 0 0 0
48 $self->{line_lengths} = {
49 public => $self->{line_lengths},
50 notice => $self->{line_lengths},
51 privmsg => $self->{line_lengths},
52 0 };
53 }
54 else {
55 $self->{line_lengths} = {
56 public => 350,
57 notice => 350,
58 privmsg => 350,
59 0 %{ $self->{line_lengths} },
60 };
61 }
62  
63  
64 return POE::Component::WWW::Lipsum->spawn(
65 debug => $self->{debug},
66 0 );
67 }
68  
69 0 ▶sub _make_response_message {
Subroutine _make_response_message: not called CC=6 SCAR=37.4
70 0 my ( $self, $in_ref ) = @_;
71  
72 0 ▶ if ( $in_ref->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_ref->{"error"}) 0 0 0
73 0 return [ $in_ref->{error} ];
74 }
75  
76 0 my $text = join ' ', @{ $in_ref->{lipsum} };
77  
78 0 $text =~ s/\s+/ /g;
79  
80 0 ▶ my $line_max_length = $self->{line_lengths}{ $in_ref->{_type} } || 350;
Condition0%0/2
$self->{'line_lengths'}{$in_ref->{'_type'}} || 350
l!l
00
MC/DC0%0/1
$self->{'line_lengths'}{$in_ref->{'_type'}} || 350
$self->{'line_lengths'}{$in_ref->{'_type'}}
Truth table0%0/2
A
A= $self->{'line_lengths'}{$in_ref->{'_type'}}
Aresult
11
00
81  
82 0 ▶ while ( length( $text ) > $line_max_length ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $text > $line_max_length) 0 0 0
83 0 push @{ $in_ref->{out} }, substr $text, 0, $line_max_length;
84 0 $text = substr $text, $line_max_length;
85 }
86 0 push @{ $in_ref->{out} }, $text;
87  
88 0 my $line_num_max = $self->{max_lines}{ $in_ref->{_type} };
89 0 ▶ unless ( defined $line_num_max ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line_num_max) 0 0 0
90 0 ▶ if ( $in_ref->{_type} eq 'public' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_ref->{'_type'} eq 'public') { } 0 0 0
91 0 $line_num_max = 1;
92 }
93 else {
94 0 $line_num_max = 5;
95 }
96 }
97  
98 0 @{ $in_ref->{out} } = splice @{ $in_ref->{out} }, 0, $line_num_max;
99  
100 0 return $in_ref->{out};
101 }
102  
103 0 ▶sub _make_response_event {
Subroutine _make_response_event: not called CC=2 SCAR=17.9
104 0 my $self = shift;
105 0 my $in_ref = shift;
106  
107 return {
108 lipsum => $in_ref->{lipsum},
109  
110 ( exists $in_ref->{error}
111 ? ( error => $in_ref->{error} )
112 : ( out => $in_ref->{out}, )
113 ),
114  
115 0 ▶ map { $_ => $in_ref->{"_$_"} }
Branch: 1 branch
BranchTrueFalseTotal
exists $in_ref->{'error'} ? : 0 0 0
116 qw( who channel message type what ),
117 }
118 }
119  
120 0 ▶sub _make_poco_call {
Subroutine _make_poco_call: not called CC=6 SCAR=37.4
121 0 my $self = shift;
122 0 my $data_ref = shift;
123  
124 0 my %args;
125 @args{ qw/amount what start html/ }
126 0 = map lc, split m|[/\s,]+|, $data_ref->{what};
127  
128 0 ▶ $args{what} ||= 'words';
Condition0%0/2
$args{"what"} ||= "words"
l!l
00
MC/DC0%0/1
$args{"what"} ||= "words"
$args{"what"}
Truth table0%0/2
A
A= $args{"what"}
Aresult
11
00
129 0 ▶ $args{amount} ||= '15';
Condition0%0/2
$args{"amount"} ||= 15
l!l
00
MC/DC0%0/1
$args{"amount"} ||= 15
$args{"amount"}
Truth table0%0/2
A
A= $args{"amount"}
Aresult
11
00
130  
131 0 ▶ if ( defined $args{html} and $args{html} =~ /yes/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'html'} and $args{'html'} =~ /yes/) { } 0 0 0
Condition0%0/3
defined $args{"html"} and $args{"html"} =~ /yes/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"html"} and $args{"html"} =~ /yes/
defined $args{"html"} $args{"html"} =~ /yes/
Truth table0%0/3
A and B
A= defined $args{"html"}B= $args{"html"} =~ /yes/
ABresult
0X0
100
111
132 0 $args{html} = 1
133 }
134 else {
135 0 delete $args{html};
136 }
137  
138 0 my %max_amount_for = (
139 words => 7000,
140 paras => 100,
141 lists => 100,
142 bytes => 56000,
143 );
144  
145 0 ▶ if ( $args{amount} > $max_amount_for{ $args{what} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"amount"} > $max_amount_for{$args{"what"}}) 0 0 0
146 0 $args{amount} = $max_amount_for{ $args{what} };
147 }
148  
149 $self->{poco}->generate( {
150 event => '_poco_done',
151 args => \%args,
152 0 map +( "_$_" => $data_ref->{$_} ),
153 keys %$data_ref,
154 }
155 );
156 }
157  
158  
159 1 1;
160 __END__
« Plugin/Validator/CSS.pm ↑ Summary Plugin/CSS/SelectorTools.pm »