| 1 | package LyricFinder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | require 5.001; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use parent 'LyricFinder::_Class'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # LyricFinder - A Derived work, by (c) 2020-2026 Jim Turner <turnerjw784 at yahoo.com> of: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # Lyrics Fetcher | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # Copyright (C) 2007-2020 David Precious <davidp@preshweb.co.uk> (CPAN: BIGPRESH) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # Originally authored by and copyright (C) 2003 Sir Reflog <reflog@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # who kindly passed maintainership on to David Precious in Feb 2007 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # Original idea: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # Copyright (C) 2003 Zachary P. Landau <kapheine@hypa.net> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # the Free Software Foundation; either version 2 of the License, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # (at your option) any later version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # along with this program; if not, write to the Free Software | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | our $VERSION = '1.60'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | our $DEBUG = 0; # If you want debug messages, set debug to a true value | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my @supported_mods = (qw(Cache ApiLyricsOvh AZLyrics Genius Letras Lrclib Musixmatch)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | my %haveit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | foreach my $module (@supported_mods) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 7 | $haveit{$module} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | eval "use LyricFinder::$module; \$haveit{$module} = 1; 1"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | #EXTRACT ANY MAIN-SPECIFIC ARGUMENTS (NOT TO BE PASSED TO SUBMODULES): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my @args = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $arg = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($arg =~ /^\-omit$/o) { #ALLOW USER TO OMIT SPECIFIC INSTALLED SUBMODULE(S): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $omit = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my @omitModules = ref($omit) ? @{$omit} : split(/\,\s*/, $omit); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | foreach my $omit (@omitModules) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $haveit{$omit} = 0 if (defined($haveit{$omit}) && $haveit{$omit}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $haveit{$omit} and $haveit{$omit}
MC/DC0%0/2
defined $haveit{$omit} and $haveit{$omit}
defined $haveit{$omit}
$haveit{$omit}
Truth table0%0/3
A and B
A= defined $haveit{$omit}B= $haveit{$omit}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | push @args, $arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $self = $class->SUPER::new('', @args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # @{$self->{'_fetchers'}} = @FETCHERS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | @{$self->{'_fetchers'}} = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | @{$self->{'_FETCHERS'}} = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | #NOTE: UPPER CASE _FETCHERS USED FOR "random" AND "all", & *NEVER* INCLUDES CACHE (1ST SUBMODULE TRIES CACHE)!: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | #LOWER CASE _fetchers INCLUDES CACHE FIRST IF CACHE DIRECTORY AND IT'S NOT WRITEONLY, AS THIS IS FOR ORDER/TRIED LIST! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | foreach my $module (@supported_mods) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | next unless ($haveit{$module} && $module ne 'Cache'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$haveit{$module} and $module ne "Cache"
MC/DC0%0/2
$haveit{$module} and $module ne "Cache"
$haveit{$module}
$module ne "Cache"
Truth table0%0/3
A and B
A= $haveit{$module}B= $module ne "Cache"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | push @{$self->{'_FETCHERS'}}, $module; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | push @{$self->{'_fetchers'}}, $module; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | unshift(@{$self->{'_fetchers'}}, 'Cache') if ($haveit{'Cache'} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | && $self->{'-cache'} && $self->{'-cache'} !~ /^\>/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$haveit{"Cache"} and $self->{"-cache"} and not $self->{"-cache"} =~ /^\>/
$haveit{"Cache"} and $self->{"-cache"}
MC/DC0%0/3
$haveit{"Cache"} and $self->{"-cache"} and not $self->{"-cache"} =~ /^\>/
$haveit{"Cache"}
$self->{"-cache"}
not $self->{"-cache"} =~ /^\>/
Truth table0%0/4
A and B and not(C)
A= $haveit{"Cache"}B= $self->{"-cache"}C= not $self->{"-cache"} =~ /^\>/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | bless $self, $class; #BLESS IT! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub order { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
order: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return wantarray ? split(/\,/, $self->{'Order'}) : $self->{'Order'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub tried { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tried: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return wantarray ? split(/\,/, $self->{'Tried'}) : $self->{'Tried'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub _fetch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fetch: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my ($self, $artist, $title, $fetchers) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $self->_debug("LyricFinder::_fetch($artist, $title, $fetchers)!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if (!$artist || !$title || ref $artist || ref $title) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
not $artist && $title or ref $artist or ref $title
not $artist && $title or ref $artist
$artist && $title
MC/DC0%0/4
not $artist && $title or ref $artist or ref $title
$artist
$title
ref $artist
ref $title
Truth table0%0/5
not(A && B) or C or D
A= $artistB= $titleC= ref $artistD= ref $title
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | carp("e:_fetch() called without artist and title."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if (!$fetchers || ref $fetchers ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $fetchers or ref $fetchers ne "ARRAY"
MC/DC0%0/2
not $fetchers or ref $fetchers ne "ARRAY"
not $fetchers
ref $fetchers ne "ARRAY"
Truth table0%0/3
not(A) or B
A= not $fetchersB= ref $fetchers ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | carp("e:_fetch not given arrayref of fetchers to try"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | for my $fetcher (@$fetchers) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $self->{'Url'} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $self->_debug("..Trying fetcher $fetcher for artist:$artist title:$title"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $fetcherpkg = __PACKAGE__ . "::$fetcher"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $finderModule = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | eval "\$finderModule = new ${fetcherpkg}(\%{\$self});"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($@ || !$finderModule) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or not $finderModule
MC/DC0%0/2
$@ or not $finderModule
$@
not $finderModule
Truth table0%0/3
A or not(B)
A= $@B= not $finderModule
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | carp("w:Failed to load sub-module $fetcherpkg ($@)"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # OK, we require()d this fetcher, try using it: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $self->{'Error'} = 'Ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $self->_debug("..Source module $fetcher loaded OK"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $self->{'Tried'} .= "$fetcher,"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if (!$finderModule->can('fetch')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->_debug("e:Source LyricFinder::$fetcher can't ->fetch($finderModule->{'Error'})"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $self->_debug("..Trying to fetch with $fetcher"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $lyrics = $finderModule->fetch($artist, $title); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->{'Error'} = $finderModule->message(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $self->{'Url'} = $finderModule->url(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ($self->{'Error'} eq 'Ok') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $self->_debug("..Source: $fetcher returned lyrics"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if (defined($lyrics) && $lyrics =~ /\S/o) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $lyrics and $lyrics =~ /\S/o
MC/DC0%0/2
defined $lyrics and $lyrics =~ /\S/o
defined $lyrics
$lyrics =~ /\S/o
Truth table0%0/3
A and B
A= defined $lyricsB= $lyrics =~ /\S/o
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $self->{'Source'} = $finderModule->source();; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $self->{'Site'} = $finderModule->site(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $self->{'image_url'} = $finderModule->image_url(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | @{$self->{'Credits'}} = $finderModule->credits(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $self->{'Tried'} =~ s/\,$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $self->_debug("i:Lyrics fetched from: ".$self->{'Source'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | return $lyrics; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # if we get here, we tried all sites we were asked to try, and none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # of them worked. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | $self->{'Error'} = 'e:All sites failed to fetch lyrics!' if ($#{$fetchers} > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $self->{'Tried'} =~ s/\,$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=24 SCAR=64.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my ($self, $artist, $title, $fetcherspec, $limit) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my @tryfetchers = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $self->_debug("LyricFinder::fetch($artist, $title, $fetcherspec)!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $self->{'Tried'} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $fetcherspec = 'random' unless (defined $fetcherspec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | unless (ref $fetcherspec) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $fetcherspec = 'random' unless ($fetcherspec =~ /\w/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $fetcherspec = [split /\s*\,\s*/, $fetcherspec], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | $fetcherspec = ['random'] unless ($#{$fetcherspec} >= 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if ($#{$fetcherspec} > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $specstring = join('|',@{$fetcherspec}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if ($specstring =~ /\b(Cache|auto|all)\b/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | carp("s:'$1' can only be used by itself, not in a list!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $self->{'Source'} = 'none'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # we've got an arrayref of fetchers to use: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my %usedSources = (); #avoid including any module name more than once in the list. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | for my $fetcher (@{$fetcherspec}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if (grep /$fetcher/, @{$self->{'_FETCHERS'}}) { #VALID FETCHER(S) SPECIFIED: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | push @tryfetchers, $fetcher; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $usedSources{$fetcher} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } elsif ($fetcher =~ m'^random$'i) { #"random" SPECIFIED (CONVERTS TO A RANDOM LIST OF FETCHERS: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my $random_fetcher; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my $usedcnt = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | foreach my $t (@tryfetchers) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $usedSources{$t} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ++$usedcnt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my $fetchersCnt = scalar(@{$self->{'_FETCHERS'}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $maxcnt = ($fetchersCnt - $#{$fetcherspec}) + $usedcnt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | $maxcnt -= ($fetchersCnt - $limit) if (defined($limit) && $limit > 0 && $fetchersCnt > $limit); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $limit and $limit > 0 and $fetchersCnt > $limit
defined $limit and $limit > 0
MC/DC0%0/3
defined $limit and $limit > 0 and $fetchersCnt > $limit
defined $limit
$limit > 0
$fetchersCnt > $limit
Truth table0%0/4
A and B and C
A= defined $limitB= $limit > 0C= $fetchersCnt > $limit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | #NOTE: usedcnt = # OF ITEMS (IF ANY) SPECIFIED LEFT OF "random"! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | while (scalar(@tryfetchers) < $maxcnt) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $random_fetcher = int(rand(scalar @{$self->{'_FETCHERS'}})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | unless ($usedSources{${$self->{'_FETCHERS'}}[$random_fetcher]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$usedSources{do {
$$self{"_FETCHERS"}
}->[$random_fetcher]} or grep /do {
$$self{"_FETCHERS"}
}->[$random_fetcher]/, @{$fetcherspec;}
MC/DC0%0/2
$usedSources{do {
$$self{"_FETCHERS"}
}->[$random_fetcher]} or grep /do {
$$self{"_FETCHERS"}
}->[$random_fetcher]/, @{$fetcherspec;}
$usedSources{do {
$$self{"_FETCHERS"}
}->[$random_fetcher]}
grep /do {
$$self{"_FETCHERS"}
}->[$random_fetcher]/, @{$fetcherspec;}
Truth table0%0/3
A or B
A= $usedSources{do {
$$self{"_FETCHERS"}
}->[$random_fetcher]}B= grep /do {
$$self{"_FETCHERS"}
}->[$random_fetcher]/, @{$fetcherspec;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | || grep(/${$self->{'_FETCHERS'}}[$random_fetcher]/, @{$fetcherspec})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | push @tryfetchers, ${$self->{'_FETCHERS'}}[$random_fetcher]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $usedSources{${$self->{'_FETCHERS'}}[$random_fetcher]} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $usedcnt++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | ▶ | } elsif ($fetcher =~ m'^Cache$'i && $haveit{'Cache'}) { #The Cache MODULE SPECIFIED: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$fetcher =~ /^Cache$/i and $haveit{"Cache"}
MC/DC0%0/2
$fetcher =~ /^Cache$/i and $haveit{"Cache"}
$fetcher =~ /^Cache$/i
$haveit{"Cache"}
Truth table0%0/3
A and B
A= $fetcher =~ /^Cache$/iB= $haveit{"Cache"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | @tryfetchers = ('Cache'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | last; #these values can only be used once (first) & by itself! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } elsif ($fetcher =~ m'^A(?:uto|ll)$'i) { #"auto" or "all" SPECIFIED (SYNONYMS): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | @tryfetchers = @{$self->{'_FETCHERS'}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } else { #INVALID MODULE-NAME OR VALUE SPECIFIED, SKIP: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | carp("e:$fetcher isn't a valid fetcher, ignoring"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | $#tryfetchers = $limit - 1 if (defined($limit) && $limit > 0 && $limit <= $#tryfetchers); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $limit and $limit > 0 and $limit <= $#tryfetchers
defined $limit and $limit > 0
MC/DC0%0/3
defined $limit and $limit > 0 and $limit <= $#tryfetchers
defined $limit
$limit > 0
$limit <= $#tryfetchers
Truth table0%0/4
A and B and C
A= defined $limitB= $limit > 0C= $limit <= $#tryfetchers
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | unless ($#tryfetchers >= 0) { #NO VALID MODULE NAMES S SPECIFIED (PUNT)!: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | carp("s:No valid fetchers specified!") ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $self->{'Order'} = join(',', @tryfetchers); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return $self->_fetch($artist, $title, \@tryfetchers); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } # end of sub fetch. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||