File Coverage

blib/lib/MP3/Album/Layout/Fetcher.pm
Criterion Covered Total %
statement 9 25 36.0
branch 0 12 0.0
condition 0 3 0.0
subroutine 3 5 60.0
pod 0 2 0.0
total 12 47 25.5


line stmt bran cond sub pod time code
1             package MP3::Album::Layout::Fetcher;
2              
3 1     1   1387 use strict;
  1         2  
  1         36  
4 1     1   1724 use Data::Dumper;
  1         12738  
  1         88  
5 1     1   10 use MP3::Album::Layout;
  1         1  
  1         789  
6              
7             @__PACKAGE__::FETCHERS = ();
8             my $myname = __PACKAGE__;
9             my $me = $myname;
10             $me =~ s/\:\:/\//g;
11              
12             foreach my $d (@INC) {
13             chomp $d;
14             if (-d "$d/$me/") {
15             local(*F_DIR);
16             opendir(*F_DIR, "$d/$me/");
17             while ( my $b = readdir(*F_DIR)) {
18             next unless $b =~ /^(.*)\.pm$/;
19             push @__PACKAGE__::FETCHERS, $1;
20             }
21             }
22             }
23              
24              
25             sub available_fetchers {
26 0 0   0 0   return wantarray ? @__PACKAGE__::FETCHERS : \@__PACKAGE__::FETCHERS;
27             }
28              
29             sub fetch {
30 0     0 0   my $c = shift;
31 0           my %a = @_;
32              
33 0 0 0       unless ($a{album} && ( ref($a{album}) eq 'MP3::Album') ) {
34 0           $@ = "Need a MP3::Album";
35 0           return undef;
36             }
37 0 0         unless ( grep /^$a{method}$/, @__PACKAGE__::FETCHERS ) {
38 0           $@ = "Need a valid method to use (".join(',',@__PACKAGE__::FETCHERS).")";
39 0           return undef;
40             }
41              
42 0           my $fetcher = __PACKAGE__."::$a{method}";
43 0           eval "require $fetcher";
44 0 0         if ($@) {
45 0           return undef;
46             }
47              
48 0           my $f = $fetcher->fetch(%a);
49              
50 0 0         return undef unless $f;
51              
52 0 0         return wantarray ? @$f : $f;
53             }
54              
55             1;
56              
57             =head1 NAME
58              
59             MP3::Album::Layout::Fetcher - Perl extension to manage fetchers of album layouts.
60              
61             =head1 DESCRIPTION
62              
63             This module is a fetcher manager. It searches for modules in the MP3::Album::Layout::Fetcher::* name space and registers them as available fetchers.
64              
65             The fetcher modules are called by MP3::Album::Layout::Fetcher and they return lists of album layouts (MP3::Album::Layout).
66              
67             This module calls the respective Fetcher->fetch() method and returns the result.
68              
69             In case of error the Fetchers must return undef with the error description in $@.
70              
71             The fetcher selection is made by the "method" parameter passed to the fetch() of this module.
72              
73             The value of the "method" parameter must be a * part of the MP3::Album::Layout::Fetcher::* fetcher package name. (i.e. for MP3::Album::Layout::Fetcher::CDDB the method is CDDB).
74              
75             =head1 BUGS
76              
77             There are no known bugs, if catch one please let me know.
78              
79             =head1 CONTACT AND COPYRIGHT
80              
81             Copyright 2003 Bruno Tavares . All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
82              
83             =cut