File Coverage

blib/lib/Data/Fake/Text.pm
Criterion Covered Total %
statement 31 31 100.0
branch 2 2 100.0
condition 4 9 44.4
subroutine 12 12 100.0
pod 3 3 100.0
total 52 57 91.2


line stmt bran cond sub pod time code
1 3     3   59684 use 5.008001;
  3         15  
2 3     3   12 use strict;
  3         4  
  3         48  
3 3     3   11 use warnings;
  3         3  
  3         134  
4              
5             package Data::Fake::Text;
6             # ABSTRACT: Fake text data generators
7              
8             our $VERSION = '0.004';
9              
10 3     3   13 use Exporter 5.57 qw/import/;
  3         28  
  3         145  
11              
12             our @EXPORT = qw(
13             fake_words
14             fake_sentences
15             fake_paragraphs
16             );
17              
18 3     3   643 use Data::Fake::Core qw/_transform/;
  3         4  
  3         656  
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 18     18 1 5479 my ($count) = @_;
36 18         776 require Text::Lorem;
37 18   66     963 $LOREM ||= Text::Lorem->new;
38 18     18   85 return sub { $LOREM->words( _transform($count) ) };
  18         44  
39             }
40              
41             #pod =func fake_sentences
42             #pod
43             #pod $generator = fake_sentences(); # single fake sentence
44             #pod $generator = fake_sentences($n); # N sentences
45             #pod $generator = fake_sentences( fake_int(1, 3) ); # random number of them
46             #pod
47             #pod Returns a generator that provides L sentences. The argument
48             #pod is the number of sentences to return (or a code reference to provide the
49             #pod number of sentences); the default is one.
50             #pod
51             #pod =cut
52              
53             sub fake_sentences {
54 6     6 1 6234 my ($count) = @_;
55 1     1   2 return sub { "" }
56 6 100       17 if $count == 0;
57 5         21 require Text::Lorem;
58 5   33     11 $LOREM ||= Text::Lorem->new;
59 5     5   18 return sub { $LOREM->sentences( _transform($count) ) };
  5         13  
60             }
61              
62             #pod =func fake_paragraphs
63             #pod
64             #pod $generator = fake_paragraphs(); # single fake paragraph
65             #pod $generator = fake_paragraphs($n); # N paragraph
66             #pod $generator = fake_paragraphs( fake_int(1, 3) ); # random number of them
67             #pod
68             #pod Returns a generator that provides L paragraphs. The argument
69             #pod is the number of paragraphs to return (or a code reference to provide the
70             #pod number of paragraphs); the default is one.
71             #pod
72             #pod =cut
73              
74             sub fake_paragraphs {
75 6     6 1 8014 my ($count) = @_;
76 6         24 require Text::Lorem;
77 6   33     13 $LOREM ||= Text::Lorem->new;
78 6     6   21 return sub { $LOREM->paragraphs( _transform($count) ) };
  6         11  
79             }
80              
81             1;
82              
83              
84             # vim: ts=4 sts=4 sw=4 et tw=75:
85              
86             __END__