blib/lib/Text/Lorem.pm

filter: Statementstmt 100% 47 / 47 Branchbran 100% 6 / 6 Conditioncond 80.0% 4 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 13 / 13 Podpod 40.0% 4 / 10 totaltotal 89.2% 75 / 84 CC 9 SCAR 7.2
CC
9
Cov
98%
words
3.0
sentences
3.0
paragraphs
3.0
CRAP 2.1
↑ Summary
1 package Text::Lorem;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 $VERSION = "0.34";
8  
9 5 my $lorem_singleton;
10  
11 9 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
12 9 my $class = shift;
13 9 ▶ $lorem_singleton ||= bless {},$class;
Condition100%2/2
$lorem_singleton ||= bless({}, $class)
l!l
45
MC/DC100%1/1
$lorem_singleton ||= bless({}, $class)
$lorem_singleton
Truth table100%2/2
A
A= $lorem_singleton
Aresult
11
00
14 9 return $lorem_singleton;
15 }
16  
17 3 ▶sub generate_wordlist {
Subroutine generate_wordlist: called CC=1 SCAR=0.0
Pod undocumented
18 3 my $self = shift;
19 3 return [ map { s/\W//; lc($_) }split(/\s+/, <DATA>) ];
20 }
21  
22 218 ▶sub wordlist {
Subroutine wordlist: called CC=2 SCAR=7.1
Pod undocumented
23 218 my $self = shift;
24 218 ▶ return $self->{ wordlist } ||= $self->generate_wordlist();
Condition66%2/3
$self->{"wordlist"} ||= $self->generate_wordlist
l!l&&r!l&&!r
21530
MC/DC0%0/2
$self->{"wordlist"} ||= $self->generate_wordlist
$self->{"wordlist"} $self->generate_wordlist
Truth table66%2/3
A ||= B
A= $self->{"wordlist"}B= $self->generate_wordlist
ABresult
1X1
011
000
25 }
26  
27 218 ▶sub wordcount {
Subroutine wordcount: called CC=1 SCAR=0.0
Pod undocumented
28 218 my $self = shift;
29 218 return scalar(@{$self->{ wordlist }});
30 }
31  
32 218 ▶sub get_word {
Subroutine get_word: called CC=1 SCAR=0.0
Pod undocumented
33 218 my $self = shift;
34 218 return $self->wordlist->[ int( rand( $self->wordcount ) ) ];
35 }
36  
37 33 ▶sub words {
Subroutine words: called CC=3 SCAR=11.0
Pod documented
38 33 my $self = shift;
39 33 my $num = shift;
40 33 my @words;
41 33 push @words, $self->get_word() for (1..$num);
42 33 ▶ return wantarray ? @words : join ' ', @words;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 32 33
43 }
44  
45 31 ▶sub get_sentence {
Subroutine get_sentence: called CC=1 SCAR=0.0
Pod undocumented
46 31 my $self = shift;
47 31 my $words = $self->words( 4 + int( rand( 6 ) ) ) . '.';
48 31 return ucfirst( $words );
49 }
50  
51 8 ▶sub sentences {
Subroutine sentences: called CC=3 SCAR=11.0
Pod documented
52 8 my $self = shift;
53 8 my $num = shift;
54 8 my @sentences;
55 8 push @sentences, $self->get_sentence for (1..$num);
56 8 ▶ return wantarray ? @sentences : join ' ', @sentences;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 7 8
57 }
58  
59 6 ▶sub get_paragraph {
Subroutine get_paragraph: called CC=1 SCAR=0.0
Pod undocumented
60 6 my $self = shift;
61 6 my $paragraph = $self->sentences(3 + int( rand( 4 ) ) );
62 6 return $paragraph;
63 }
64  
65 2 ▶sub paragraphs {
Subroutine paragraphs: called CC=3 SCAR=11.0
Pod documented
66 2 my $self = shift;
67 2 my $num = shift;
68 2 my @paragraphs;
69 2 push @paragraphs, $self->get_paragraph for (1..$num);
70 2 ▶ return wantarray ? @paragraphs : join "\n\n", @paragraphs;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
71 }
72  
73 5 1;
74  
75 =pod
76  
77 =head1 NAME
78  
79 Text::Lorem - Generate random Latin looking text
80  
81 =head1 SYNOPSIS
82  
83 use Text::Lorem;
84  
85 my $text = Text::Lorem->new();
86  
87 # Generate a string of text with 5 words
88 $words = $text->words(5);
89  
90 # Generate a list of 5 words
91 @words = $text->words(5);
92  
93 # Generate a string of text with 2 sentences
94 $sentences = $text->sentences(2);
95  
96 # Generate a list of 2 sentences
97 @sentences = $text->sentences(2);
98  
99 # Generate a string of text with 3 paragraphs
100 $paragraphs = $text->paragraphs(3);
101  
102 # Generate a list of 3 paragraphs
103 @paragraphs = $text->paragraphs(3);
104  
105 =head1 DESCRIPTION
106  
107 Often when developing a website or other application it's important to have placeholders for content. This module generates
108 prescribed amounts of fake Latin text.
109  
110 =head1 CONSTRUCTOR
111  
112 =over 4
113  
114 =item C<new()>
115  
116 The default constructor, C<new()> takes no arguments and returns a Text::Lorem object.
117  
118 =back
119  
120 =head1 METHODS
121  
122 All methods below will return a string in scalar context or list in list context.
123  
124 =over 4
125  
126 =item C<words( INTEGER )>
127  
128 Returns INTEGER fake Latin words.
129  
130 =item C<sentences( INTEGER )>
131  
132 Returns INTEGER sentences in fake Latin.
133  
134 =item C<paragraphs( INTEGER )>
135  
136 Returns INTEGER paragraphs of fake Latin text.
137  
138 =back
139  
140 =head1 THANKS
141  
142 Thanks to the guys who pushed me off the cliff called comfort and into the scary world of Perl: James Duncan, Leon Brocard.
143  
144 =head1 AUTHOR
145  
146 Adeola Awoyemi (adeola@cpan.org)
147  
148 =head1 SEE ALSO
149  
150 L<WWW::Lipsum> and L<http://lipsum.com/>
151  
152 =head1 COPYRIGHT
153  
154 Copyright (c) 2003 by Adeola Awoyemi.
155 This software is released under the same license as Perl itself.
156  
157 =cut
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185 __DATA__
↑ Summary