File Coverage

blib/lib/AudioFile/Info/Build.pm
Criterion Covered Total %
statement 12 38 31.6
branch 0 18 0.0
condition 0 18 0.0
subroutine 4 5 80.0
pod 1 1 100.0
total 17 80 21.2


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