blib/lib/Lingua/ManagementSpeak.pm

filter: Statementstmt 99.2% 124 / 125 Branchbran 98.2% 57 / 58 Conditioncond 83.3% 30 / 36 MC/DCmcdc 70.0% 14 / 20 Subroutinesub 100% 16 / 16 Podpod 100% 11 / 11 totaltotal 94.7% 252 / 266 CC 48 SCAR 18.2
CC
48
Cov
96%
words
10.0
body
10.0
to_html
8.0
CRAP 6.2
↑ Summary
1 package Lingua::ManagementSpeak;
2 # ABSTRACT: Tool to generate managerial-sounding text and full documents
3  
4 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '1.07'; # VERSION
9  
10 1 ▶sub new {
Subroutine new: called CC=2 SCAR=8.1
Pod documented
11 1 my $self = shift;
12 1 ▶ return bless( {
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
13 pronouns => [ qw( I we they ) ],
14 articles => [ qw( the your my our its ) ],
15 conj_adverbs => [ qw( however moreover nevertheless consequently ) ],
16 conjuntors => [ 'though', 'although', 'notwithstanding that', 'yet', 'still' ],
17 sub_conjuncs => [
18 'after', 'although', 'as', 'as if', 'as long as', 'as though', 'because',
19 'before', 'even if', 'even though', 'if', 'if only', 'in order that',
20 'now that', 'once', 'since', 'so that', 'though',
21 'unless', 'until', 'when', 'whenever', 'where', 'whereas', 'wherever',
22 'while'
23 ],
24 power_words => [ qw(
25 accomplished dealt implemented projected achieved debated improved
26 promoted acquired decided included proofed adjusted defined increased
27 purchased administered delegated indicated qualified advised delivered
28 initiated questioned analyzed demonstrated inspected rated applied
29 designed instructed received appraised determined insured recognized
30 arranged developed interpreted recommended assessed devised interviewed
31 recorded assisted directed introduced recruited assured discovered
32 investigated reduced awarded dispensed joined rehabilitated bought
33 displayed kept related briefed distributed launched renovated brought
34 earned led repaired budgeted edited located reported calculated educated
35 maintained represented cataloged elected managed researched chaired
36 encouraged maximized reviewed changed enlisted measured revised
37 classified ensured mediated selected closed entertained modified served
38 coached established motivated simplified combined evaluated named
39 sketched communicated examined negotiated sold compared excelled
40 observed solved completed executed obtained spearheaded computed
41 exhibited operated specified conceived expanded ordered started
42 concluded expedited organized streamlined conducted explained paid
43 strengthened confronted facilitated participated studied constructed
44 financed perceived suggested continued forecast performed summarized
45 contracted formulated persuaded supervised controlled gained placed
46 targeted convinced gathered planned taught coordinated graded predicted
47 tested corrected greeted prepared trained corresponded guided presented
48 translated counseled handled processed treated created helped produced
49 updated critiqued identified programmed wrote
50 ) ],
51 verbs => [ qw(
52 aggregate architect benchmark brand cultivate deliver deploy
53 disintermediate drive e-enable embrace empower enable engage engineer
54 enhance envision evolve expedite exploit extend facilitate generate grow
55 implement incentivize incubate innovate integrate iterate
56 leverage maximize mesh monetize morph optimize orchestrate
57 recontextualize reintermediate reinvent repurpose revolutionize scale
58 seize strategize streamline syndicate synergize synthesize target
59 transform transition unleash utilize visualize whiteboard
60 ) ],
61 aux_verbs => [
62 'will', 'shall', 'may', 'might', 'can', 'could', 'must',
63 'ought to', 'should', 'would', 'need to'
64 ],
65 adjectives => [ qw (
66 24/365 24/7 B2B B2C back-end best-of-breed bleeding-edge
67 bricks-and-click clicks-and-mortar collaborative compelling
68 cross-platform cross-media customized cutting-edge
69 distributed dot-com dynamic e-business efficient
70 end-to-end enterprise extensible frictionless front-end
71 global granular holistic impactful innovative integrated interactive
72 intuitive killer leading-edge magnetic mission-critical next-generation
73 one-to-one open-source out-of-the-box plug-and-play proactive real-time
74 revolutionary robust scalable seamless sexy sticky strategic synergistic
75 transparent turn-key ubiquitous user-centric value-added vertical
76 viral virtual visionary web-enabled wireless world-class
77 )],
78 nouns => [ qw(
79 action-item application architecture bandwidth channel community
80 content convergence deliverable e-business e-commerce e-market
81 e-service e-tailer experiences functionality infomediary
82 infrastructure initiative interface market methodology metric
83 mindshare model network niche paradigm partnership platform
84 portal relationship ROI synergy web-readiness schema solution
85 supply-chain system technology user
86 ) ],
87 nounss => [ qw(
88 action-items applications architectures channels communities
89 convergences deliverables e-businesses e-commerces e-markets
90 e-services e-tailers experiences eyeballs functionalities infomediaries
91 infrastructures initiatives interfaces markets methodologies metrics
92 models networks niches paradigms partnerships platforms
93 portals relationships synergies schemas solutions
94 supply-chains systems technologies users vortals
95 ) ],
96 }, ref($self) || $self );
97 }
98  
99 8051 ▶sub _random {
Subroutine _random: called CC=3 SCAR=11.1
100 8051 ▶ my $high = shift || 5;
Condition50%1/2
shift() || 5
l!l
80510
MC/DC0%0/1
shift() || 5
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
101 8051 ▶ my $low = shift || 1;
Condition100%2/2
shift() || 1
l!l
17976254
MC/DC100%1/1
shift() || 1
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
102 8051 return int( rand( $high - $low + 1 ) ) + $low;
103 }
104  
105 574 ▶sub words {
Subroutine words: called CC=10 SCAR=23.0
Pod documented
106 574 my ( $self, $meta ) = @_;
107  
108 # deal with "maybe_n/n_word" meta words
109 574 ▶ while ( $meta =~ /maybe[_-](\d+)\/(\d+)[_-](\w+)\S*/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta =~ m[maybe[_-](\d+)/(\d+)[_-](\w+)\S*]) 1421 574 1995
110 1421 ▶ my $word = ( _random( $2, $1 ) == $1 ) ? $3 : '';
Branch: 1 branch
BranchTrueFalseTotal
_random($2, $1) == $1 ? : 544 877 1421
111 1421 ▶ if ($word) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word) { } 544 877 1421
112 544 $meta =~ s/maybe[_-]\d+\/\d+[_-]\w+(\S*)/$word$1/;
113 }
114 else {
115 877 $meta =~ s/maybe[_-]\d+\/\d+[_-]\w+\S*\s*//;
116 }
117 }
118  
119 # convert "phrase" into phrase meta words
120 574 $meta =~ s/(\w)\s+phrase/$1, phrase/g;
121 574 $meta =~ s/phrase/conjuntor article noun to_be power_word/g;
122  
123 574 ▶ while ( $meta =~ /(
Branch: 1 branch
BranchTrueFalseTotal
if ($meta =~ /( pronoun|article|sub_conjuc|power_word|verb|aux_verb| adjective|noun|conj_adverb|conjuntor|sub_conjunc|adverb )/x) 5712 574 6286
124 pronoun|article|sub_conjuc|power_word|verb|aux_verb|
125 adjective|noun|conj_adverb|conjuntor|sub_conjunc|adverb
126 )/x ) {
127 # if the word is an adverb, we have to pick a verb and add "ing" to it
128 5712 my ( $t1, $t2 ) = ( $1, $1 );
129 5712 ▶ $t2 = 'verb' if ( $t1 eq 'adverb' );
Branch: 1 branch
BranchTrueFalseTotal
if $t1 eq "adverb" 19 5693 5712
130 5712 my $word = $self->{ $t2 . 's' }[ _random( $#{ $self->{ $t2 . 's' } }, 0 ) ];
131 5712 ▶ $word =~ s/[e]*$/ing/ if ( $t1 eq 'adverb' );
Branch: 1 branch
BranchTrueFalseTotal
if $t1 eq "adverb" 19 5693 5712
132 5712 $meta =~ s/$t1/$word/;
133 }
134  
135 # convert "to_be" into the proper conjugated form
136 574 ▶ while ( $meta =~ /\b(\w+)\s+to_be/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta =~ /\b(\w+)\s+to_be/) 165 574 739
137 165 ▶ if ( $1 =~ /ess$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($1 =~ /ess$/) { } 9 156 165
elsif ($1 =~ /s$/) { } 7 149 156
138 9 $meta =~ s/to_be/is/;
139 }
140 elsif ( $1 =~ /s$/ ) {
141 7 $meta =~ s/to_be/are/;
142 }
143 else {
144 149 $meta =~ s/to_be/is/;
145 }
146 }
147  
148 574 $meta =~ s/^\s+|\s+$//;
149 574 $meta =~ s/\b(a)(\s[aeiouy])/$1n$2/i;
150  
151 574 return $meta;
152 }
153  
154 483 ▶sub sentence {
Subroutine sentence: called CC=2 SCAR=6.9
Pod documented
155 483 my ( $self, $is_first ) = @_;
156  
157 483 my @meta = (
158 'article noun to_be power_word sub_conjunc pronoun verb ' .
159 'article maybe_1/2_adjective noun maybe_1/3_phrase',
160 'sub_conjunc pronoun power_word article maybe_1/2_adjective ' .
161 'noun, article maybe_1/2_adjective noun power_word article ' .
162 'maybe_1/2_adjective noun maybe_1/4_phrase',
163 'pronoun aux_verb verb article maybe_1/2_adjective noun ' .
164 'sub_conjunc article adjective noun aux_verb verb article ' .
165 'maybe_1/2_adjective noun maybe_1/5_phrase',
166 'sub_conjunc pronoun verb article maybe_1/2_adjective noun, ' .
167 'pronoun can verb article ' .
168 'maybe_1/2_adjective noun maybe_1/4_phrase',
169 'pronoun aux_verb verb article maybe_1/2_adjective noun ' .
170 'sub_conjunc pronoun verb article ' .
171 'maybe_1/2_adjective noun maybe_1/5_phrase',
172 'article noun verbs adjective noun',
173 'article noun to_be a adjective noun, sub_conjunc article noun verbs article noun',
174 );
175  
176 483 my $meta = $meta[ _random( 6, 0 ) ];
177 483 ▶ $meta = 'maybe_1/4_conj_adverb, ' . $meta if ( not $is_first );
Branch: 1 branch
BranchTrueFalseTotal
unless $is_first 383 100 483
178  
179 483 return ucfirst( $self->words($meta) ) . '.';
180 }
181  
182 99 ▶sub paragraph {
Subroutine paragraph: called CC=3 SCAR=11.0
Pod documented
183 99 my ( $self, $low, $high ) = @_;
184 99 my $count = 0;
185 99 ▶ if ( not defined $low ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $low) { } 80 19 99
elsif (not defined $high) { } 4 15 19
186 80 $count = _random( 7, 4 );
187 }
188 elsif ( not defined $high ) {
189 4 $count = $low;
190 }
191 else {
192 15 $count = _random( $high, $low );
193 }
194 99 $count--;
195 99 return join( ' ', $self->sentence(1), map { $self->sentence } ( 1 .. $count ) );
196 }
197  
198 92 ▶sub paragraphs {
Subroutine paragraphs: called CC=2 SCAR=7.0
Pod documented
199 92 my $self = shift;
200 92 ▶ my $count = shift || 2;
Condition50%1/2
shift() || 2
l!l
920
MC/DC0%0/1
shift() || 2
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
201 92 my ( $low, $high ) = @_;
202 92 return map { $self->paragraph( $low, $high ) } ( 1 .. $count );
203 }
204  
205 42 ▶sub bullets {
Subroutine bullets: called CC=2 SCAR=6.9
Pod documented
206 42 my ( $self, $meta ) = ( shift, '' );
207 42 ▶ my $count = shift || 5;
Condition100%2/2
shift() || 5
l!l
411
MC/DC100%1/1
shift() || 5
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
208  
209 42 my @bullet_forms = (
210 'power_word article adjective noun',
211 'power_word adjective noun',
212 'power_word adjective noun and power_word adjective noun',
213 'power_word article noun power_word by article noun',
214 );
215  
216 42 return map { ucfirst $self->words( $bullet_forms[ _random( @bullet_forms - 1, 0 ) ] ) } ( 1 .. $count );
217 }
218  
219 42 ▶sub body {
Subroutine body: called CC=10 SCAR=23.0
Pod documented
220 42 my ( $self, $params ) = @_;
221  
222 42 ▶ $params->{p_min} = 1 if ( not exists $params->{p_min} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{"p_min"} 36 6 42
223 42 ▶ $params->{p_max} = 3 if ( not exists $params->{p_max} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{"p_max"} 36 6 42
224 42 ▶ $params->{b_freq} = 25 if ( not exists $params->{b_freq} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{"b_freq"} 36 6 42
225 42 ▶ $params->{b_min} = 3 if ( not exists $params->{b_min} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{"b_min"} 36 6 42
226 42 ▶ $params->{b_max} = 6 if ( not exists $params->{b_max} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{"b_max"} 36 6 42
227  
228 42 my @data = ();
229 42 my $p_count = _random( $params->{p_max}, $params->{p_min} );
230  
231 42 foreach ( 1 .. $p_count ) {
232 push @data, {
233 type => 'paragraph',
234 89 text => $self->paragraphs (1, $params->{p_s_min}, $params->{p_s_max} ),
235 };
236  
237 # a bulletted list should never be first in a body block
238 89 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($_ != $p_count and _random(100, 1) < $params->{"b_freq"}) 9 80 89
Condition100%3/3
$_ != $p_count and _random(100, 1) < $params->{"b_freq"}
!ll&&!rl&&r
42389
MC/DC100%2/2
$_ != $p_count and _random(100, 1) < $params->{"b_freq"}
$_ != $p_count _random(100, 1) < $params->{"b_freq"}
Truth table100%3/3
A and B
A= $_ != $p_countB= _random(100, 1) < $params->{"b_freq"}
ABresult
0X0
100
111
239 ( $_ != $p_count ) and
240 ( _random(100, 1 ) < $params->{b_freq} )
241 ) {
242 9 my $type = _random( 4, 1 );
243 push @data, {
244 type => 'bullet',
245 text => $self->bullets( 1, $type )
246 9 } foreach ( 1 .. _random( $params->{b_max}, $params->{b_min} ) );
247 }
248 }
249  
250 42 return \@data;
251 }
252  
253 42 ▶sub header {
Subroutine header: called CC=4 SCAR=13.9
Pod documented
254 42 my ( $self, $level ) = @_;
255  
256 42 my $meta = [
257 [
258 'noun and noun',
259 'noun',
260 'article noun',
261 ],
262 'power_word noun',
263 'adverb power_word noun',
264 'adverb power_word adjective noun',
265 'power_word adjective noun adverb noun',
266 ];
267  
268 42 ▶ $meta = $meta->[ $level - 1 ] if ($level);
Branch: 1 branch
BranchTrueFalseTotal
if $level 41 1 42
269 42 ▶ $meta = $meta->[ _random( @$meta - 1, 0 ) ] while ( ref($meta) );
Branch: 1 branch
BranchTrueFalseTotal
ref $meta and do { $meta = $$meta[_random(@$meta - 1, 0)] } 11 42 53
270  
271 # capitalize every word with the exception of: of, and, or
272 return join( ' ', map {
273 42 ▶ join( '-', map { ( $_ !~ /^(of|and|or)$/ ) ? ucfirst : $_ } split('-') )
Branch: 1 branch
BranchTrueFalseTotal
!($_ =~ /^(of|and|or)$/) ? : 109 1 110
274 } split( ' ', $self->words($meta) ) );
275 }
276  
277 4 ▶sub structure {
Subroutine structure: called CC=5 SCAR=16.1
Pod documented
278 4 my ( $self, $depth, $last_push ) = ( shift, 1, 0 );
279 4 ▶ my $block_limit = shift || 3;
Condition100%2/2
shift() || 3
l!l
13
MC/DC100%1/1
shift() || 3
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
280 4 ▶ my $depth_limit = shift || 3;
Condition100%2/2
shift() || 3
l!l
13
MC/DC100%1/1
shift() || 3
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
281 4 ▶ my $mimimum_length = shift || 10;
Condition100%2/2
shift() || 10
l!l
13
MC/DC100%1/1
shift() || 10
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
282 4 my @structure = ();
283  
284 4 my $structure;
285 29 ▶ $structure = sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
286 29 my $block = 0;
287 29 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($block < _random($block_limit, 1) and _random(4, 1) > 1 || $last_push ne $depth) 57 29 86
Condition66%4/6
$block < _random($block_limit, 1) and _random(4, 1) > 1 || $last_push ne $depth
!ll&&!rl&&r
29057
_random(4, 1) > 1 or $last_push ne $depth
l!l&&r!l&&!r
46110
MC/DC33%1/3
$block < _random($block_limit, 1) and _random(4, 1) > 1 || $last_push ne $depth
$block < _random($block_limit, 1) _random(4, 1) > 1 $last_push ne $depth
Truth table75%3/4
A and B or C
A= $block < _random($block_limit, 1)B= _random(4, 1) > 1C= $last_push ne $depth
ABCresult
0XX0
1000
11X1
1011
288 ( $block < _random( $block_limit, 1 ) ) and
289 ( ( _random( 4, 1 ) > 1 ) or ( $last_push ne $depth ) )
290 # 1/4 chance of exiting early
291 ) {
292 57 push( @structure, $depth );
293 57 my $last_push = $depth;
294 57 $block++;
295 57 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($depth < $depth_limit and _random(5, 1) > 1) 23 34 57
Condition100%3/3
$depth < $depth_limit and _random(5, 1) > 1
!ll&&!rl&&r
26823
MC/DC100%2/2
$depth < $depth_limit and _random(5, 1) > 1
$depth < $depth_limit _random(5, 1) > 1
Truth table100%3/3
A and B
A= $depth < $depth_limitB= _random(5, 1) > 1
ABresult
0X0
100
111
296 ( $depth < $depth_limit ) and
297 ( _random( 5, 1 ) > 1 )
298 # 1/5 chance of not nesting
299 ) {
300 23 $depth++;
301 23 $structure->();
302 }
303 }
304 29 $depth--;
305 4 };
306  
307 4 ▶ while ( @structure < $mimimum_length ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@structure < $mimimum_length) 6 4 10
308 6 ( $last_push, $depth ) = ( 0, 1 );
309 6 $structure->();
310 }
311 4 return @structure;
312 }
313  
314 3 ▶sub document {
Subroutine document: called CC=3 SCAR=11.0
Pod documented
315 3 my $self = shift;
316 3 ▶ my $structure = shift || [ $self->structure ];
Condition100%2/2
shift() || [$self->structure]
l!l
12
MC/DC100%1/1
shift() || [$self->structure]
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
317 3 ▶ my $params = shift || undef;
Condition100%2/2
shift() || undef
l!l
12
MC/DC100%1/1
shift() || undef
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
318  
319 return [ map {
320 {
321 type => 'header' . $_,
322 text => $self->header($_)
323 40 }, @{ $self->body($params) }
324 3 } ( @{$structure} ) ];
325 }
326  
327 1 ▶sub to_html {
Subroutine to_html: called CC=8 SCAR=20.8
Pod documented
328 1 my ( $self, $data ) = @_;
329 1 my ( $inside_list, $output ) = ( 0, '' );
330  
331 1 for ( @{$data} ) {
332 59 ▶ if ( ( $_->{type} ne 'bullet' ) and ($inside_list) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"type"} ne "bullet" and $inside_list) 3 56 59
Condition100%3/3
$_->{"type"} ne "bullet" and $inside_list
!ll&&!rl&&r
15413
MC/DC100%2/2
$_->{"type"} ne "bullet" and $inside_list
$_->{"type"} ne "bullet" $inside_list
Truth table100%3/3
A and B
A= $_->{"type"} ne "bullet"B= $inside_list
ABresult
0X0
100
111
333 3 $inside_list = 0;
334 3 $output .= "</ul>\n";
335 }
336  
337 59 ▶ if ( $_->{type} =~ /header(\d+)/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($_->{'type'} =~ /header(\d+)/) { } 13 46 59
elsif ($_->{'type'} eq 'paragraph') { } 31 15 46
elsif ($_->{'type'} eq 'bullet') { } 15 0 15
338 13 $output .= '<h' . $1 . '>' . $_->{text} . '</h' . $1 . ">\n";
339 }
340 elsif ( $_->{type} eq 'paragraph' ) {
341 31 $output .= '<p>' . $_->{text} . "</p>\n";
342 }
343 elsif ( $_->{type} eq 'bullet' ) {
344 15 ▶ my $ul = (not $inside_list) ? "<ul>\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
!$inside_list ? : 3 12 15
345 15 $inside_list++;
346 15 $output .= $ul . '<li>' . $_->{text} . "</li>\n";
347 }
348 else {
349 0 $output .= '<pre>' . $_->{text} . "</pre>\n";
350 }
351 }
352  
353 1 return $output;
354 }
355  
356 2 1;
357  
358 __END__
↑ Summary