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   111023 use strict;
  1         1  
  1         18  
4 1     1   3 use warnings;
  1         1  
  1         21  
5              
6 1     1   3 use base 'Module::Build';
  1         1  
  1         41  
7              
8 1     1   41011 use YAML qw(LoadFile DumpFile);
  1         3747  
  1         250  
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 ($mp3, $ogg);
36              
37 0             for (qw(read write)) {
38 0 0             $mp3 += 50 if $config->{$pkg}{"${_}_mp3"};
39               }
40              
41 0             for (qw(read write)) {
42 0 0             $ogg +=50 if $config->{$pkg}{"${_}_ogg"};
43               }
44              
45             # prefer non-perl implementations
46 0 0           unless ($config->{$pkg}{pure_perl}) {
47 0 0             $mp3 += 10 if $mp3;
48 0 0             $ogg += 10 if $ogg;
49               }
50              
51             # if no default set and this plugin has a score, or if this plugin
52             # score higher than the existing default, then set default
53 0 0 0         if (! exists $config->{default}{mp3} and $mp3
      0        
      0        
54                  or $mp3 and $mp3 >= $config->{default}{mp3}{score}) {
55 0               $config->{default}{mp3} = { name => $pkg, score => $mp3 };
56 0               warn "AudioFile::Info - Default mp3 handler is now $pkg\n";
57               }
58              
59 0 0 0         if (! exists $config->{default}{ogg} and $ogg
      0        
      0        
60                  or $ogg and $ogg >= $config->{default}{ogg}{score}) {
61 0               $config->{default}{ogg} = { name => $pkg, score => $ogg };
62 0               warn "AudioFile::Info - Default ogg handler is now $pkg\n";
63               }
64              
65 0             DumpFile($path, $config);
66             }
67              
68             1;
69              
70             =head1 NAME
71            
72             AudioFile::Info::Build - Build utilities for AudioFile::Info.
73            
74             =head1 DESCRIPTION
75            
76             This is a module which is used as part of the build system for
77             AudioFile::Info plugins.
78            
79             See L<AudioFile::Info> for more details.
80            
81             =head1 METHODS
82            
83             =head2 ACTION_install
84            
85             Overrides the ACTION_install method from Module::Build.
86            
87             =head1 AUTHOR
88            
89             Dave Cross, E<lt>dave@dave.org.ukE<gt>
90            
91             =head1 COPYRIGHT AND LICENSE
92            
93             Copyright 2003 by Dave Cross
94            
95             This library is free software; you can redistribute it and/or modify
96             it under the same terms as Perl itself.
97            
98             =cut
99              
100