| 1 | package Text::Greeking; | ||||||||||||||||||||||||||||
| 2 | 2 | $Text::Greeking::VERSION = '0.15'; | |||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # make controllable eventually. | ||||||||||||||||||||||||||||
| 8 | 2 | my @punc = split('', '..........??!'); | |||||||||||||||||||||||||||
| 9 | 2 | my @inpunc = split('', ',,,,,,,,,,;;:'); | |||||||||||||||||||||||||||
| 10 | 2 | push @inpunc, ' --'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 14 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 15 | 0 | srand; | |||||||||||||||||||||||||||
| 16 | 0 | $self->init; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 0 | $_[0]->sources([]); | |||||||||||||||||||||||||||
| 21 | 0 | $_[0]->paragraphs(2, 8); | |||||||||||||||||||||||||||
| 22 | 0 | $_[0]->sentences(2, 8); | |||||||||||||||||||||||||||
| 23 | 0 | $_[0]->words(5, 15); | |||||||||||||||||||||||||||
| 24 | 0 | $_[0]; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub sources { | ||||||||||||||||||||||||||
|
Subroutine
sources: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $_[0]->{sources} = $_[1] if defined $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | $_[0]->{sources}; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub add_source { | ||||||||||||||||||||||||||
|
Subroutine
add_source: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 0 | my ($self, $text) = @_; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | return unless $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | $text =~ s/[\n\r]/ /g; | |||||||||||||||||||||||||||
| 36 | 0 | $text =~ s/[[:punct:]]//g; | |||||||||||||||||||||||||||
| 37 | 0 | my @words = map { lc $_ } split /\s+/, $text; | |||||||||||||||||||||||||||
| 38 | 0 | push @{$self->{sources}}, \@words; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub generate { | ||||||||||||||||||||||||||
|
Subroutine
generate: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 43 | 0 | my $out; | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | $self->_load_default_source unless defined $self->{sources}->[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | my @words = @{$self->{sources}->[int(rand(@{$self->{sources}}))]}; | |||||||||||||||||||||||||||
| 46 | 0 | my ($paramin, $paramax) = @{$self->{paragraphs}}; | |||||||||||||||||||||||||||
| 47 | 0 | my ($sentmin, $sentmax) = @{$self->{sentences}}; | |||||||||||||||||||||||||||
| 48 | 0 | my ($phramin, $phramax) = @{$self->{words}}; | |||||||||||||||||||||||||||
| 49 | 0 | my $pcount = int(rand($paramax - $paramin + 1) + $paramin); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | for (my $x = 0; $x < $pcount; $x++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | my $p; | |||||||||||||||||||||||||||
| 53 | 0 | my $scount = int(rand($sentmax - $sentmin + 1) + $sentmin); | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | for (my $y = 0; $y < $scount; $y++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | my $s; | |||||||||||||||||||||||||||
| 56 | 0 | my $wcount = int(rand($phramax - $phramin + 1) + $phramin); | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | for (my $w = 0; $w < $wcount; $w++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | my $word = $words[int(rand(@words))]; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | $s .= $s ? " $word" : ucfirst($word); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $s .= | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$w + 1 < $wcount and not int rand 10
MC/DC0%0/2
$w + 1 < $wcount and not int rand 10
$w + 1 < $wcount
not int rand 10
Truth table0%0/3
A and not(B)
A= $w + 1 < $wcountB= not int rand 10
| |||||||||||||||||||||||||||||
| 61 | (($w + 1 < $wcount) && !int(rand(10))) | ||||||||||||||||||||||||||||
| 62 | ? $inpunc[int(rand(@inpunc))] | ||||||||||||||||||||||||||||
| 63 | : ''; | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | $s .= $punc[int(rand(@punc))]; | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | $p .= ' ' if $p; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $p .= $s; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 0 | $out .= $p . "\n\n"; # assumes text. | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | $out; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub paragraphs { $_[0]->{paragraphs} = [$_[1], $_[2]] } | ||||||||||||||||||||||||||
|
Subroutine
paragraphs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub sentences { $_[0]->{sentences} = [$_[1], $_[2]] } | ||||||||||||||||||||||||||
|
Subroutine
sentences: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub words { $_[0]->{words} = [$_[1], $_[2]] } | ||||||||||||||||||||||||||
|
Subroutine
words: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub _load_default_source { | ||||||||||||||||||||||||||
|
Subroutine
_load_default_source: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 79 | 0 | my $text = <<TEXT; | |||||||||||||||||||||||||||
| 80 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit, | ||||||||||||||||||||||||||||
| 81 | sed diam nonummy nibh euismod tincidunt ut laoreet dolore | ||||||||||||||||||||||||||||
| 82 | magna aliquam erat volutpat. Ut wisi enim ad minim veniam, | ||||||||||||||||||||||||||||
| 83 | quis nostrud exerci tation ullamcorper suscipit lobortis | ||||||||||||||||||||||||||||
| 84 | nisl ut aliquip ex ea commodo consequat. Duis autem vel eum | ||||||||||||||||||||||||||||
| 85 | iriure dolor in hendrerit in vulputate velit esse molestie | ||||||||||||||||||||||||||||
| 86 | consequat, vel illum dolore eu feugiat nulla facilisis at | ||||||||||||||||||||||||||||
| 87 | vero eros et accumsan et iusto odio dignissim qui blandit | ||||||||||||||||||||||||||||
| 88 | praesent luptatum zzril delenit augue duis dolore te feugait | ||||||||||||||||||||||||||||
| 89 | nulla facilisi. | ||||||||||||||||||||||||||||
| 90 | Ut wisi enim ad minim veniam, quis nostrud exerci tation | ||||||||||||||||||||||||||||
| 91 | ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo | ||||||||||||||||||||||||||||
| 92 | consequat. Duis autem vel eum iriure dolor in hendrerit in | ||||||||||||||||||||||||||||
| 93 | vulputate velit esse molestie consequat, vel illum dolore eu | ||||||||||||||||||||||||||||
| 94 | feugiat nulla facilisis at vero eros et accumsan et iusto | ||||||||||||||||||||||||||||
| 95 | odio dignissim qui blandit praesent luptatum zzril delenit | ||||||||||||||||||||||||||||
| 96 | augue duis dolore te feugait nulla facilisi. Lorem ipsum | ||||||||||||||||||||||||||||
| 97 | dolor sit amet, consectetuer adipiscing elit, sed diam | ||||||||||||||||||||||||||||
| 98 | nonummy nibh euismod tincidunt ut laoreet dolore magna | ||||||||||||||||||||||||||||
| 99 | aliquam erat volutpat. | ||||||||||||||||||||||||||||
| 100 | Duis autem vel eum iriure dolor in hendrerit in vulputate | ||||||||||||||||||||||||||||
| 101 | velit esse molestie consequat, vel illum dolore eu feugiat | ||||||||||||||||||||||||||||
| 102 | nulla facilisis at vero eros et accumsan et iusto odio | ||||||||||||||||||||||||||||
| 103 | dignissim qui blandit praesent luptatum zzril delenit augue | ||||||||||||||||||||||||||||
| 104 | duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit | ||||||||||||||||||||||||||||
| 105 | amet, consectetuer adipiscing elit, sed diam nonummy nibh | ||||||||||||||||||||||||||||
| 106 | euismod tincidunt ut laoreet dolore magna aliquam erat | ||||||||||||||||||||||||||||
| 107 | volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci | ||||||||||||||||||||||||||||
| 108 | tation ullamcorper suscipit lobortis nisl ut aliquip ex ea | ||||||||||||||||||||||||||||
| 109 | commodo consequat. | ||||||||||||||||||||||||||||
| 110 | TEXT | ||||||||||||||||||||||||||||
| 111 | 0 | $_[0]->add_source($text); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 2 | 1; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||||||