File Coverage

blib/lib/AudioFile/Info/Build.pm
Criterion Covered Total %
statement 12 37 32.4
branch 0 12 0.0
condition 0 6 0.0
subroutine 4 5 80.0
pod 1 1 100.0
total 17 61 27.8


line stmt bran cond sub pod time code
1             package AudioFile::Info::Build;
2              
3 2     2   435219 use strict;
  2         14  
  2         125  
4 2     2   13 use warnings;
  2         14  
  2         182  
5              
6 2     2   35 use base 'Module::Build';
  2         3  
  2         5761  
7              
8 2     2   337977 use YAML qw(LoadFile DumpFile);
  2         20662  
  2         1205  
9              
10             sub ACTION_install {
11 0     0 1   my $self = shift;
12              
13 0           $self->SUPER::ACTION_install(@_);
14              
15 0           require AudioFile::Info;
16              
17 0 0         die "Can't find the installation of AudioFile::Info\n" if $@;
18              
19 0           my $pkg = $self->notes('package');
20              
21 0           my $path = $INC{'AudioFile/Info.pm'};
22              
23 0           $path =~ s/Info.pm$/plugins.yaml/;
24              
25 0           my $config;
26              
27 0 0         if (-f $path) {
28 0           $config = LoadFile($path);
29             }
30              
31 0           $config->{$pkg} = $self->notes('config');
32              
33             # calculate "usefulness" score
34              
35 0           my ($score);
36 0           my @types = qw[ogg mp3];
37 0           my @modes = qw[read write];
38              
39 0           for my $type (@types) {
40 0           for my $mode (@modes) {
41 0 0         $score->{$type} += 50 if $config->{$pkg}{"${mode}_${type}"};
42             }
43             }
44              
45             # prefer non-perl implementations
46 0 0         unless ($config->{$pkg}{pure_perl}) {
47 0           for (@types) {
48 0 0         $score->{$_} += 10 if $score->{$_};
49             }
50             }
51              
52             # if no default set and this plugin has a score, or if this plugin
53             # score higher than the existing default, then set default
54 0           for (@types) {
55 0 0 0       if ($score->{$_} and (not exists $config->{default}{$_}
      0        
56             or $score->{$_} >= $config->{default}{$_}{score})) {
57 0           $config->{default}{$_} = { name => $pkg, score => $score->{$_} };
58 0           warn "AudioFile::Info - Default $_ handler is now $pkg\n";
59             }
60             }
61              
62 0           DumpFile($path, $config);
63             }
64              
65             1;
66              
67             =head1 NAME
68              
69             AudioFile::Info::Build - Build utilities for AudioFile::Info.
70              
71             =head1 DESCRIPTION
72              
73             This is a module which is used as part of the build system for
74             AudioFile::Info plugins.
75              
76             See L for more details.
77              
78             =head1 METHODS
79              
80             =head2 ACTION_install
81              
82             Overrides the ACTION_install method from Module::Build.
83              
84             =head1 AUTHOR
85              
86             Dave Cross, Edave@perlhacks.comE
87              
88             =head1 COPYRIGHT AND LICENSE
89              
90             Copyright 2003 by Dave Cross
91              
92             This library is free software; you can redistribute it and/or modify
93             it under the same terms as Perl itself.
94              
95             =cut
96