| 1 | package Acme::Text::Rhombus; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use constant LINES => 25; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use constant FILLUP => '.'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use constant FORWARD => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | our ($VERSION, @EXPORT_OK, %EXPORT_TAGS); | |||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | my @subs; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | $VERSION = '0.25'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | @subs = qw(rhombus rhombus_letter rhombus_digit rhombus_random); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | @EXPORT_OK = @subs; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | %EXPORT_TAGS = ('all' => [ @subs ]); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | my $get_opt = sub | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 23 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 23 | my ($opts, $opt, $regex, $default) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 21 | return (exists $opts->{$opt} | ||||||||||||||||||||||||||||||||||||||||||
| 22 | && defined $opts->{$opt} | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 23 | ▶ | and $opts->{$opt} =~ $regex) ? $opts->{$opt} : $default; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
exists $opts->{$opt} and defined $opts->{$opt} and $opts->{$opt} =~ /$regex/
exists $opts->{$opt} and defined $opts->{$opt}
MC/DC33%1/3
exists $opts->{$opt} and defined $opts->{$opt} and $opts->{$opt} =~ /$regex/
exists $opts->{$opt}
defined $opts->{$opt}
$opts->{$opt} =~ /$regex/
Truth table50%2/4
A and B and C
A= exists $opts->{$opt}B= defined $opts->{$opt}C= $opts->{$opt} =~ /$regex/
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | sub _draw_rhombus | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_rhombus: called CC=18 SCAR=29.1
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | my ($mode, $lines, $char, $case, $fillup, $forward) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | my ($is_letter, $is_digit, $is_random) = ($mode eq 'letter', $mode eq 'digit', $mode eq 'random'); | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | my %alter = ( | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | lower => sub { lc $_[0] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | ▶ | upper => sub { uc $_[0] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | ▶ | $char = $alter{$case}->($char) if $is_letter; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | my @chars = map chr, (48..57, 65..90, 97..122); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | ▶ | $char = $chars[int(rand(@chars))] unless defined $char; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | ▶ | $lines++ if $lines % 2 == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | my ($line, $repeat, $rhombus); | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | ▶ | for ($line = $repeat = 1; $line <= $lines; $line++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 117 | my $spaces = ($lines - $repeat) / 2; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 117 | $rhombus .= $fillup x $spaces; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 117 | $rhombus .= $char x $repeat; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 117 | $rhombus .= $fillup x $spaces; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 117 | $rhombus .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 117 | ▶ | $repeat = $line < ($lines / 2) ? $repeat + 2 : $repeat - 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 117 | ▶ | if ($is_letter) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 71 | ▶ | $char = $forward ? chr(ord($char) + 1) : chr(ord($char) - 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | elsif ($is_digit) { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 46 | ▶ | $char = $forward ? $char + 1 : $char - 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | elsif ($is_random) { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $char = $chars[int(rand(@chars))]; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 117 | ▶ | if ($is_letter && $char !~ /[a-zA-Z]/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$is_letter and not $char =~ /[a-zA-Z]/
MC/DC100%2/2
$is_letter and not $char =~ /[a-zA-Z]/
$is_letter
not $char =~ /[a-zA-Z]/
Truth table100%3/3
A and not(B)
A= $is_letterB= not $char =~ /[a-zA-Z]/
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | $char = $alter{$case}->($forward ? 'a' : 'z'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | ▶ | elsif ($is_digit and $char > 9 || $char < 0) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$is_digit and $char > 9 || $char < 0
$char > 9 or $char < 0
MC/DC100%3/3
$is_digit and $char > 9 || $char < 0
$is_digit
$char > 9
$char < 0
Truth table100%4/4
A and B or C
A= $is_digitB= $char > 9C= $char < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | ▶ | $char = $forward ? 0 : 9; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | return $rhombus; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | sub rhombus { return rhombus_letter(@_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rhombus: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | sub rhombus_letter | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rhombus_letter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | my $lines = $get_opt->(\%opts, 'lines', qr/^\d+$/, LINES); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | my $letter = $get_opt->(\%opts, 'letter', qr/^[a-zA-Z]$/, 'a'); | |||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | my $case = $get_opt->(\%opts, 'case', qr/^(?:low|upp)er$/, 'upper'); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | my $fillup = $get_opt->(\%opts, 'fillup', qr/^\S$/, FILLUP); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | my $forward = $get_opt->(\%opts, 'forward', qr/^[01]$/, FORWARD); | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | return _draw_rhombus('letter', $lines, $letter, $case, $fillup, $forward); | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | sub rhombus_digit | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rhombus_digit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | my $lines = $get_opt->(\%opts, 'lines', qr/^\d+$/, LINES); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | my $digit = $get_opt->(\%opts, 'digit', qr/^\d$/, 0); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | my $fillup = $get_opt->(\%opts, 'fillup', qr/^\S$/, FILLUP); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | my $forward = $get_opt->(\%opts, 'forward', qr/^[01]$/, FORWARD); | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | return _draw_rhombus('digit', $lines, $digit, undef, $fillup, $forward); | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | sub rhombus_random | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rhombus_random: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $lines = $get_opt->(\%opts, 'lines', qr/^\d+$/, LINES); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $fillup = $get_opt->(\%opts, 'fillup', qr/^\S$/, FILLUP); | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return _draw_rhombus('random', $lines, undef, undef, $fillup, undef); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 114 | __END__ | ||||||||||||||||||||||||||||||||||||||||||