| 1 | package Acme::Laugh; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use version; $VERSION = qv('0.0.5'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our @ISA = qw( Exporter ); | |||||||||||||||||||||||||||
| 11 | 2 | our %EXPORT_TAGS = ('all' => [qw( laugh )]); | |||||||||||||||||||||||||||
| 12 | 2 | our @EXPORT_OK = (@{$EXPORT_TAGS{'all'}}); | |||||||||||||||||||||||||||
| 13 | 2 | our @EXPORT = qw(); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # Module implementation here | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | my @incipit = ('', qw( m b mb )); | |||||||||||||||||||||||||||
| 18 | 2 | my @alto = qw( w u ); | |||||||||||||||||||||||||||
| 19 | 2 | my @basso = qw( a e ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =encoding iso-8859-1 | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =begin Private | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =over | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =item incipit() | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | Returns the incipit of the laugh. No parameters. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =item minichunk( $first ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | Returns a chunk of a laugh. It is compound of one to three letters. | ||||||||||||||||||||||||||||
| 34 | The input parameter forces the inclusion of the first letter, for reasons | ||||||||||||||||||||||||||||
| 35 | too difficult to explain here. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =item continuum( $chunks ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | Returns the join of a $chunks number of elements, where $chunks defaults | ||||||||||||||||||||||||||||
| 40 | to 1 + rand 4; | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =item capitals( $laugh ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | Returns the input $laugh where some of the letters are capitalised in | ||||||||||||||||||||||||||||
| 45 | a random fashion. | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =back | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =end Private | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | ▶ | sub incipit { return $incipit[rand @incipit]; } | ||||||||||||||||||||||||||
|
Subroutine
incipit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 20 | ▶ | sub minichunk { | ||||||||||||||||||||||||||
|
Subroutine
minichunk: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 20 | my ($dopre) = @_; | |||||||||||||||||||||||||||
| 57 | 20 | my $pre = $alto[rand @alto]; | |||||||||||||||||||||||||||
| 58 | 20 | ▶ | $pre = '' if (!$dopre) && (rand > 0.5); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $dopre and rand > "0.5"
MC/DC100%2/2
not $dopre and rand > "0.5"
not $dopre
rand > "0.5"
Truth table100%3/3
not(A) and B
A= not $dopreB= rand > "0.5"
| |||||||||||||||||||||||||||||
| 59 | 20 | ▶ | my $post = (rand > 0.5) ? 'h' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 20 | my $chunk = join '', $pre, $basso[rand @basso], $post; | |||||||||||||||||||||||||||
| 61 | 20 | return ($chunk, $post); | |||||||||||||||||||||||||||
| 62 | } ## end sub minichunk | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | sub continuum { | ||||||||||||||||||||||||||
|
Subroutine
continuum: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | my $chunks = shift || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 66 | 2 | ▶ | $chunks = 1 + rand 4 if $chunks < 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 2 | my $p = 0; | |||||||||||||||||||||||||||
| 68 | return join '', | ||||||||||||||||||||||||||||
| 69 | 2 | map { (my $c, $p) = minichunk(!$p); $c; } 1 .. $chunks; | |||||||||||||||||||||||||||
| 70 | } ## end sub continuum | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | ▶ | sub capitals { | ||||||||||||||||||||||||||
|
Subroutine
capitals: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 2 | ▶ | return join '', map { rand > 0.5 ? uc($_) : $_; } split //, shift; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 2 | ▶ | sub laugh { return capitals(join '', incipit(), continuum(shift)); } | ||||||||||||||||||||||||||
|
Subroutine
laugh: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||