| 1 | package Mock::Data::Plugin::Text; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Mock::Data::Plugin -exporter_setup => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Mock::Data::Charset; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Mock::Data::Util 'coerce_generator'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | our @CARP_NOT= qw( Mock::Data Mock::Data::Util ); | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Mock::Data plugin that provides text-related generators | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.04'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | our $word_generator= Mock::Data::Charset->new( | ||||||||||||||||||||||||||||||||||||||||||
| 14 | notation => 'a-z', | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 25 | ▶ | str_len => sub { 1 + int(rand 3 + rand 3 + rand 4) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | *word= $word_generator->compile; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | export(qw( word words lorem_ipsum join )); | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | sub apply_mockdata_plugin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_mockdata_plugin: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | my ($class, $mock)= @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | $mock->add_generators( | |||||||||||||||||||||||||||||||||||||||||
| 24 | 'Text::join' => \&join, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 'Text::word' => $word_generator, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 'Text::words' => \&words, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 'Text::lorem_ipsum' => \&lorem_ipsum, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 33 | ▶ | sub join { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
join: called CC=24 SCAR=36.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 33 | my $mockdata= shift; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 33 | ▶ | my $opts= @_ && ref $_[0] eq 'HASH'? shift : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 33 | ▶ | my $sep= $_[0] // ($opts && $opts->{sep}) // ' '; | ||||||||||||||||||||||||||||||||||||||||
|
Condition37%3/8
($_[0] // $opts && $opts->{"sep"}) // " "
$_[0] // $opts && $opts->{"sep"}
$opts and $opts->{"sep"}
MC/DC0%0/3
($_[0] // $opts && $opts->{"sep"}) // " "
$_[0]
$opts
$opts->{"sep"}
Truth table25%1/4
A // B and C
A= $_[0]B= $optsC= $opts->{"sep"}
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 33 | ▶ | my $source= $_[1] // ($opts && $opts->{source}) // Carp::croak("Parameter 'source' is required"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition37%3/8
($_[1] // $opts && $opts->{"source"}) // Carp::croak("Parameter 'source' is required")
$_[1] // $opts && $opts->{"source"}
$opts and $opts->{"source"}
MC/DC0%0/3
($_[1] // $opts && $opts->{"source"}) // Carp::croak("Parameter 'source' is required")
$_[1]
$opts
$opts->{"source"}
Truth table25%1/4
A // B and C
A= $_[1]B= $optsC= $opts->{"source"}
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 33 | ▶ | my $count= $_[2] // ($opts && $opts->{count}) // 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition75%6/8
($_[2] // $opts && $opts->{"count"}) // 1
$_[2] // $opts && $opts->{"count"}
$opts and $opts->{"count"}
MC/DC33%1/3
($_[2] // $opts && $opts->{"count"}) // 1
$_[2]
$opts
$opts->{"count"}
Truth table50%2/4
A // B and C
A= $_[2]B= $optsC= $opts->{"count"}
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 33 | ▶ | my $len= $opts? $opts->{len} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 33 | ▶ | my $max_len= $opts? $opts->{max_len} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 33 | ▶ | my @source_generators= map coerce_generator($_), ref $source eq 'ARRAY'? @$source : ( $source ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 33 | my $buf= $source_generators[0]->generate($mockdata); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 33 | my $src_i= 1; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 33 | ▶ | if (defined $len) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 32 | ▶ | while (length($buf) < $len && (!defined $max_len or length($buf) + length($sep) < $max_len)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
length $buf < $len and !defined($max_len) || length($buf) + length($sep) < $max_len
not defined $max_len or length($buf) + length($sep) < $max_len
MC/DC66%2/3
length $buf < $len and !defined($max_len) || length($buf) + length($sep) < $max_len
length $buf < $len
not defined $max_len
length($buf) + length($sep) < $max_len
Truth table75%3/4
A and not(B) or C
A= length $buf < $lenB= not defined $max_lenC= length($buf) + length($sep) < $max_len
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 39 | $buf .= $sep . $source_generators[$src_i++ % scalar @source_generators]->generate($mockdata); | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | my $lim= $count * scalar @source_generators; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | while ($src_i < $lim && (!defined $max_len or length($buf) + length($sep) < $max_len)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$src_i < $lim and !defined($max_len) || length($buf) + length($sep) < $max_len
not defined $max_len or length($buf) + length($sep) < $max_len
MC/DC33%1/3
$src_i < $lim and !defined($max_len) || length($buf) + length($sep) < $max_len
$src_i < $lim
not defined $max_len
length($buf) + length($sep) < $max_len
Truth table50%2/4
A and not(B) or C
A= $src_i < $limB= not defined $max_lenC= length($buf) + length($sep) < $max_len
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | $buf .= $sep . $source_generators[$src_i++ % scalar @source_generators]->generate($mockdata); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 33 | ▶ | substr($buf, $max_len)= '' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $max_len and length $buf > $max_len
MC/DC100%2/2
defined $max_len and length $buf > $max_len
defined $max_len
length $buf > $max_len
Truth table100%3/3
A and B
A= defined $max_lenB= length $buf > $max_len
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | if defined $max_len && length($buf) > $max_len; | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 33 | return $buf; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | sub words { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
words: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | my $mockdata= shift; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | ▶ | my %opts= @_ && ref $_[0] eq 'HASH'? %{ shift() } : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and ref $_[0] eq "HASH"
MC/DC50%1/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | ▶ | @opts{'len','max_len'}= ref $_[0] eq 'ARRAY'? @{$_[0]} : @_[0,0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | ▶ | $opts{source} //= $mockdata->generators->{word}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{"source"} //= $mockdata->generators->{"word"}
MC/DC0%0/2
$opts{"source"} //= $mockdata->generators->{"word"}
$opts{"source"}
$mockdata->generators->{"word"}
Truth table33%1/3
A //= B
A= $opts{"source"}B= $mockdata->generators->{"word"}
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | $mockdata->call('join', \%opts); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | my $lorem_ipsum_classic= | |||||||||||||||||||||||||||||||||||||||||
| 73 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " | ||||||||||||||||||||||||||||||||||||||||||
| 74 | ."incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis " | ||||||||||||||||||||||||||||||||||||||||||
| 75 | ."nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. " | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ."Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu " | ||||||||||||||||||||||||||||||||||||||||||
| 77 | ."fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in " | ||||||||||||||||||||||||||||||||||||||||||
| 78 | ."culpa qui officia deserunt mollit anim id est laborum. "; | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | sub lorem_ipsum { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lorem_ipsum: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | my $mockdata= shift; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | my $len= @_ > 1? $_[1] : !ref $_[0]? $_[0] : ref $_[0] eq 'HASH'? $_[0]{len} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | return $lorem_ipsum_classic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | unless defined $len; | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | my $ret= $lorem_ipsum_classic x int(1+($len/length $lorem_ipsum_classic)); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | substr($ret, $len)= ''; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | $ret =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||||||||||||||||