File Coverage

blib/lib/Data/Fake/Text.pm
Criterion Covered Total %
statement 34 34 100.0
branch 8 8 100.0
condition 4 9 44.4
subroutine 12 12 100.0
pod 3 3 100.0
total 61 66 92.4


line stmt bran cond sub pod time code
1 3     3   79739 use 5.008001;
  3         20  
2 3     3   16 use strict;
  3         5  
  3         81  
3 3     3   16 use warnings;
  3         6  
  3         185  
4              
5             package Data::Fake::Text;
6             # ABSTRACT: Fake text data generators
7              
8             our $VERSION = '0.005';
9              
10 3     3   20 use Exporter 5.57 qw/import/;
  3         40  
  3         187  
11              
12             our @EXPORT = qw(
13             fake_words
14             fake_sentences
15             fake_paragraphs
16             );
17              
18 3     3   890 use Data::Fake::Core qw/_transform/;
  3         6  
  3         933  
19              
20             my $LOREM;
21              
22             #pod =func fake_words
23             #pod
24             #pod $generator = fake_words(); # single "lorem" word
25             #pod $generator = fake_words($n); # N "lorem" words, space separated
26             #pod $generator = fake_words( fake_int(1, 3) ); # random number of them
27             #pod
28             #pod Returns a generator that provides space-separated L words.
29             #pod The argument is the number of words to return (or a code reference to
30             #pod provide the number of words); the default is one.
31             #pod
32             #pod =cut
33              
34             sub fake_words {
35 19     19 1 9341 my ($count) = @_;
36 19 100       50 $count = 1 unless defined $count;
37 19         1064 require Text::Lorem;
38 19   66     1397 $LOREM ||= Text::Lorem->new;
39 19     19   112 return sub { $LOREM->words( _transform($count) ) };
  19         52  
40             }
41              
42             #pod =func fake_sentences
43             #pod
44             #pod $generator = fake_sentences(); # single fake sentence
45             #pod $generator = fake_sentences($n); # N sentences
46             #pod $generator = fake_sentences( fake_int(1, 3) ); # random number of them
47             #pod
48             #pod Returns a generator that provides L sentences. The argument
49             #pod is the number of sentences to return (or a code reference to provide the
50             #pod number of sentences); the default is one.
51             #pod
52             #pod =cut
53              
54             sub fake_sentences {
55 7     7 1 11314 my ($count) = @_;
56 7 100       21 $count = 1 unless defined $count;
57 1     1   3 return sub { "" }
58 7 100       21 if $count == 0;
59 6         34 require Text::Lorem;
60 6   33     14 $LOREM ||= Text::Lorem->new;
61 6     6   30 return sub { $LOREM->sentences( _transform($count) ) };
  6         15  
62             }
63              
64             #pod =func fake_paragraphs
65             #pod
66             #pod $generator = fake_paragraphs(); # single fake paragraph
67             #pod $generator = fake_paragraphs($n); # N paragraph
68             #pod $generator = fake_paragraphs( fake_int(1, 3) ); # random number of them
69             #pod
70             #pod Returns a generator that provides L paragraphs. The argument
71             #pod is the number of paragraphs to return (or a code reference to provide the
72             #pod number of paragraphs); the default is one.
73             #pod
74             #pod =cut
75              
76             sub fake_paragraphs {
77 7     7 1 14133 my ($count) = @_;
78 7 100       21 $count = 1 unless defined $count;
79 7         39 require Text::Lorem;
80 7   33     21 $LOREM ||= Text::Lorem->new;
81 7     7   35 return sub { $LOREM->paragraphs( _transform($count) ) };
  7         20  
82             }
83              
84             1;
85              
86              
87             # vim: ts=4 sts=4 sw=4 et tw=75:
88              
89             __END__