| 1 | package Webservice::Rosary::API; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Util::H2O::More qw/baptise d2o/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use HTTP::Tiny qw//; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use JSON qw/decode_json/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Scalar::Util qw/reftype/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 3 | our $VERSION = "0.1.10"; | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use constant { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 3 | BASEURL => "https://the-rosary-api.vercel.app/v1", | |||||||||||||||||||||||||||||||
| 16 | DAILYURL => "https://dailyrosary.catholicdevotion.org", | ||||||||||||||||||||||||||||||||
| 17 | 3 | }; | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 12 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 20 | 12 | my $pkg = shift; | |||||||||||||||||||||||||||||||
| 21 | 12 | my %params = @_; | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 12 | ▶ | $params{timeout} = 10 if not exists $params{timeout}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 24 | 12 | ▶ | $params{cache_ttl} = 300 if not exists $params{cache_ttl}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 25 | 12 | ▶ | $params{stale_if_error} = 1 if not exists $params{stale_if_error}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 26 | 12 | ▶ | $params{cache} = {} if not exists $params{cache}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 27 | $params{ua} = _new_default_ua($params{timeout}) | ||||||||||||||||||||||||||||||||
| 28 | 12 | ▶ | if not exists $params{ua}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 12 | return baptise \%params, $pkg, | |||||||||||||||||||||||||||||||
| 31 | qw/ua timeout cache cache_ttl stale_if_error/; | ||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | sub _new_default_ua { | ||||||||||||||||||||||||||||||
|
Subroutine
_new_default_ua: called CC=4 SCAR=14.9
| |||||||||||||||||||||||||||||||||
| 36 | 1 | my $timeout = shift; | |||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | # HTTP::Tiny honors proxy environment variables. Some environments leave | ||||||||||||||||||||||||||||||||
| 39 | # those variables defined but empty; older HTTP::Tiny releases treat that | ||||||||||||||||||||||||||||||||
| 40 | # as an invalid proxy URL. Ignore only empty proxy values locally. | ||||||||||||||||||||||||||||||||
| 41 | 1 | local %ENV = %ENV; | |||||||||||||||||||||||||||||||
| 42 | 1 | foreach my $name (qw/http_proxy https_proxy all_proxy HTTP_PROXY HTTPS_PROXY ALL_PROXY/) { | |||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | delete $ENV{$name} if exists $ENV{$name} and not length $ENV{$name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $ENV{$name} and not length $ENV{$name}
MC/DC0%0/2
exists $ENV{$name} and not length $ENV{$name}
exists $ENV{$name}
not length $ENV{$name}
Truth table33%1/3
A and not(B)
A= exists $ENV{$name}B= not length $ENV{$name}
| |||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 1 | return HTTP::Tiny->new(timeout => $timeout); | |||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | sub clear_cache { | ||||||||||||||||||||||||||||||
|
Subroutine
clear_cache: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 50 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 51 | 1 | %{ $self->cache } = (); | |||||||||||||||||||||||||||||||
| 52 | 1 | return $self; | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 11 | ▶ | sub _decode_content { | ||||||||||||||||||||||||||||||
|
Subroutine
_decode_content: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||||||
| 56 | 11 | my ($self, $content, $URL) = @_; | |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 11 | ▶ | die "Rosary API returned an empty response from $URL\n" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $content and $content =~ /\S/
MC/DC0%0/2
defined $content and $content =~ /\S/
defined $content
$content =~ /\S/
Truth table33%1/3
A and B
A= defined $contentB= $content =~ /\S/
| |||||||||||||||||||||||||||||||||
| 59 | if not defined $content or $content !~ /\S/; | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 11 | my $decoded = eval { decode_json($content) }; | |||||||||||||||||||||||||||||||
| 62 | 11 | ▶ | if (not defined $decoded or $@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $decoded or $@
MC/DC50%1/2
not defined $decoded or $@
not defined $decoded
$@
Truth table66%2/3
not(A) or B
A= not defined $decodedB= $@
| |||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | my $error = $@ || q{unknown JSON decoding error}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$@ || 'unknown JSON decoding error'
MC/DC0%0/1
$@ || 'unknown JSON decoding error'
$@
Truth table50%1/2
A
A= $@
| |||||||||||||||||||||||||||||||||
| 64 | 1 | chomp $error; | |||||||||||||||||||||||||||||||
| 65 | 1 | die "Rosary API returned invalid JSON from $URL: $error\n"; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 10 | return d2o -autoundef, $decoded; | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 17 | ▶ | sub _cached_content { | ||||||||||||||||||||||||||||||
|
Subroutine
_cached_content: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 72 | 17 | my ($self, $URL, $fresh_only) = @_; | |||||||||||||||||||||||||||||||
| 73 | 17 | ▶ | return if not $self->cache_ttl or $self->cache_ttl <= 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $self->cache_ttl or $self->cache_ttl <= 0
MC/DC50%1/2
not $self->cache_ttl or $self->cache_ttl <= 0
not $self->cache_ttl
$self->cache_ttl <= 0
Truth table66%2/3
not(A) or B
A= not $self->cache_ttlB= $self->cache_ttl <= 0
| |||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 5 | ▶ | my $entry = $self->cache->{$URL} or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | return if $fresh_only and (time - $entry->{stored_at}) > $self->cache_ttl; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$fresh_only and time - $entry->{"stored_at"} > $self->cache_ttl
MC/DC100%2/2
$fresh_only and time - $entry->{"stored_at"} > $self->cache_ttl
$fresh_only
time - $entry->{"stored_at"} > $self->cache_ttl
Truth table100%3/3
A and B
A= $fresh_onlyB= time - $entry->{"stored_at"} > $self->cache_ttl
| |||||||||||||||||||||||||||||||||
| 77 | 2 | return $entry->{content}; | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 8 | ▶ | sub _cache_content { | ||||||||||||||||||||||||||||||
|
Subroutine
_cache_content: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 81 | 8 | my ($self, $URL, $content) = @_; | |||||||||||||||||||||||||||||||
| 82 | 8 | ▶ | return if not $self->cache_ttl or $self->cache_ttl <= 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $self->cache_ttl or $self->cache_ttl <= 0
MC/DC50%1/2
not $self->cache_ttl or $self->cache_ttl <= 0
not $self->cache_ttl
$self->cache_ttl <= 0
Truth table66%2/3
not(A) or B
A= not $self->cache_ttlB= $self->cache_ttl <= 0
| |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 4 | $self->cache->{$URL} = { | |||||||||||||||||||||||||||||||
| 85 | content => $content, | ||||||||||||||||||||||||||||||||
| 86 | stored_at => time, | ||||||||||||||||||||||||||||||||
| 87 | }; | ||||||||||||||||||||||||||||||||
| 88 | 4 | return; | |||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 5 | ▶ | sub _fallback_or_die { | ||||||||||||||||||||||||||||||
|
Subroutine
_fallback_or_die: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 92 | 5 | my ($self, $URL, $error) = @_; | |||||||||||||||||||||||||||||||
| 93 | 5 | chomp $error; | |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 5 | ▶ | if ($self->stale_if_error) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 96 | 5 | my $cached = $self->_cached_content($URL, 0); | |||||||||||||||||||||||||||||||
| 97 | 5 | ▶ | if (defined $cached) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 98 | 1 | warn "$error; using cached Rosary API response\n"; | |||||||||||||||||||||||||||||||
| 99 | 1 | return $self->_decode_content($cached, $URL); | |||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 4 | die "$error\n"; | |||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 14 | ▶ | sub _make_call { | ||||||||||||||||||||||||||||||
|
Subroutine
_make_call: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||
| 107 | 14 | my ($self, $when) = @_; | |||||||||||||||||||||||||||||||
| 108 | 14 | $when = lc $when; | |||||||||||||||||||||||||||||||
| 109 | 14 | my $URL = sprintf "%s/%s", BASEURL, $when; | |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | # Repeated requests are cheap locally, but preserve the semantics of | ||||||||||||||||||||||||||||||||
| 112 | # /random by never satisfying it from a fresh cache entry. | ||||||||||||||||||||||||||||||||
| 113 | 14 | ▶ | if (lc($when) ne q{random}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 114 | 12 | my $cached = $self->_cached_content($URL, 1); | |||||||||||||||||||||||||||||||
| 115 | 12 | ▶ | return $self->_decode_content($cached, $URL) if defined $cached; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 13 | my $response = eval { $self->ua->get($URL) }; | |||||||||||||||||||||||||||||||
| 119 | 13 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 120 | 1 | my $error = $@; | |||||||||||||||||||||||||||||||
| 121 | 1 | chomp $error; | |||||||||||||||||||||||||||||||
| 122 | 1 | return $self->_fallback_or_die( | |||||||||||||||||||||||||||||||
| 123 | $URL, | ||||||||||||||||||||||||||||||||
| 124 | "Rosary API request to $URL failed: $error", | ||||||||||||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | 12 | ▶ | if (ref($response) ne q{HASH}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 129 | 1 | return $self->_fallback_or_die( | |||||||||||||||||||||||||||||||
| 130 | $URL, | ||||||||||||||||||||||||||||||||
| 131 | "Rosary API request to $URL returned an invalid HTTP response", | ||||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | 11 | ▶ | if (not $response->{success}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | my $status = defined $response->{status} ? $response->{status} : q{unknown}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | 2 | ▶ | my $reason = defined $response->{reason} ? $response->{reason} : q{HTTP error}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 138 | 2 | return $self->_fallback_or_die( | |||||||||||||||||||||||||||||||
| 139 | $URL, | ||||||||||||||||||||||||||||||||
| 140 | "Rosary API request to $URL failed: HTTP $status $reason", | ||||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 9 | my $content = $response->{content}; | |||||||||||||||||||||||||||||||
| 145 | 9 | my $decoded = eval { $self->_decode_content($content, $URL) }; | |||||||||||||||||||||||||||||||
| 146 | 9 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 147 | 1 | my $error = $@; | |||||||||||||||||||||||||||||||
| 148 | 1 | chomp $error; | |||||||||||||||||||||||||||||||
| 149 | 1 | return $self->_fallback_or_die($URL, $error); | |||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 8 | $self->_cache_content($URL, $content); | |||||||||||||||||||||||||||||||
| 153 | 8 | return $decoded; | |||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 5 | ▶ | sub mp3Link { | ||||||||||||||||||||||||||||||
|
Subroutine
mp3Link: called CC=12 SCAR=26.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 157 | 5 | my ($self, $when) = @_; | |||||||||||||||||||||||||||||||
| 158 | 5 | my @mp3 = qw/today yesterday tomorrow random/; | |||||||||||||||||||||||||||||||
| 159 | 5 | ▶ | return "" if not defined $when or not grep { m/^\Q$when\E$/i } @mp3; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $when and grep {/^\Q$when\E$/i;} @mp3
MC/DC0%0/2
defined $when and grep {/^\Q$when\E$/i;} @mp3
defined $when
grep {/^\Q$when\E$/i;} @mp3
Truth table33%1/3
A and B
A= defined $whenB= grep {/^\Q$when\E$/i;} @mp3
| |||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | 5 | my $resp = $self->_make_call($when); | |||||||||||||||||||||||||||||||
| 162 | 5 | ▶ | my $type = reftype($resp) || q{}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
builtin::reftype($resp) || ''
MC/DC0%0/1
builtin::reftype($resp) || ''
builtin::reftype($resp)
Truth table50%1/2
A
A= builtin::reftype($resp)
| |||||||||||||||||||||||||||||||||
| 163 | 5 | my $item; | |||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | 5 | ▶ | if ($type eq q{ARRAY}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 166 | 4 | ▶ | $item = $resp->[0] if @$resp; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||
| 168 | elsif ($type eq q{HASH}) { | ||||||||||||||||||||||||||||||||
| 169 | 1 | $item = $resp; | |||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | 5 | ▶ | if ($item and (reftype($item) || q{}) eq q{HASH}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
$item and (builtin::reftype($item) || "") eq "HASH"
builtin::reftype($item) || ''
MC/DC50%1/2
$item and (builtin::reftype($item) || "") eq "HASH"
$item
builtin::reftype($item)
Truth table66%2/3
A and B
A= $itemB= builtin::reftype($item)
| |||||||||||||||||||||||||||||||||
| 173 | 4 | my $file = $item->{mp3Link}; | |||||||||||||||||||||||||||||||
| 174 | 4 | ▶ | return sprintf "%s/%s", DAILYURL, $file if defined $file and length $file; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $file and length $file
MC/DC0%0/2
defined $file and length $file
defined $file
length $file
Truth table33%1/3
A and B
A= defined $fileB= length $file
| |||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||
| 177 | 1 | warn "\nNo MP3 content in response from the Rosary API ... try the following links:\n"; | |||||||||||||||||||||||||||||||
| 178 | 1 | warn <<'EOF_LINKS'; | |||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | https://www.discerninghearts.com/catholic-podcasts/holy-rosary/ | ||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | + https://www.discerninghearts.com/Devotionals/Rosary-Joyful-Mysteries.mp3 | ||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | + https://www.discerninghearts.com/Devotionals/Rosary-Luminous-Mysteries.mp3 | ||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||
| 186 | + https://www.discerninghearts.com/Devotionals/Rosary-Sorrowful-Mysteries.mp3 | ||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||
| 188 | + https://www.discerninghearts.com/Devotionals/Rosary-Glorious-Mysteries.mp3 | ||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||
| 190 | ... please try back again later | ||||||||||||||||||||||||||||||||
| 191 | EOF_LINKS | ||||||||||||||||||||||||||||||||
| 192 | 1 | die "Rosary API returned no MP3 link\n"; | |||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | 9 | ▶ | sub day { | ||||||||||||||||||||||||||||||
|
Subroutine
day: called CC=7 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 196 | 9 | my ($self, $when) = @_; | |||||||||||||||||||||||||||||||
| 197 | 9 | my @days = qw/sunday monday tuesday wednesday thursday friday saturday/; | |||||||||||||||||||||||||||||||
| 198 | 9 | ▶ | return "" if not defined $when or not grep { m/^\Q$when\E$/i } @days; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $when and grep {/^\Q$when\E$/i;} @days
MC/DC50%1/2
defined $when and grep {/^\Q$when\E$/i;} @days
defined $when
grep {/^\Q$when\E$/i;} @days
Truth table66%2/3
A and B
A= defined $whenB= grep {/^\Q$when\E$/i;} @days
| |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||
| 200 | 8 | my $resp = $self->_make_call($when); | |||||||||||||||||||||||||||||||
| 201 | 4 | ▶ | my $type = reftype($resp) || q{}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
builtin::reftype($resp) || ''
MC/DC0%0/1
builtin::reftype($resp) || ''
builtin::reftype($resp)
Truth table50%1/2
A
A= builtin::reftype($resp)
| |||||||||||||||||||||||||||||||||
| 202 | 4 | ▶ | return $resp->[0] if $type eq q{ARRAY} and @$resp; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type eq "ARRAY" and @$resp
MC/DC0%0/2
$type eq "ARRAY" and @$resp
$type eq "ARRAY"
@$resp
Truth table33%1/3
A and B
A= $type eq "ARRAY"B= @$resp
| |||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | return $resp if $type eq q{HASH}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 204 | 0 | return ""; | |||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | # Get detailed recitations | ||||||||||||||||||||||||||||||||
| 208 | 2 | ▶ | sub details { | ||||||||||||||||||||||||||||||
|
Subroutine
details: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 209 | 2 | my ($self, $when) = @_; | |||||||||||||||||||||||||||||||
| 210 | 2 | my @mysteries = qw/joyful glorious sorrowful luminous/; | |||||||||||||||||||||||||||||||
| 211 | 2 | ▶ | return "" if not defined $when or not grep { m/^\Q$when\E$/i } @mysteries; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $when and grep {/^\Q$when\E$/i;} @mysteries
MC/DC50%1/2
defined $when and grep {/^\Q$when\E$/i;} @mysteries
defined $when
grep {/^\Q$when\E$/i;} @mysteries
Truth table66%2/3
A and B
A= defined $whenB= grep {/^\Q$when\E$/i;} @mysteries
| |||||||||||||||||||||||||||||||||
| 212 | 1 | return $self->_make_call($when); | |||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | 3 | 1; | |||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||
| 217 | __END__ | ||||||||||||||||||||||||||||||||