File Coverage

blib/lib/Alien/Build/Plugin/Extract/Negotiate.pm
Criterion Covered Total %
statement 40 42 95.2
branch 13 18 72.2
condition 1 3 33.3
subroutine 10 10 100.0
pod 2 2 100.0
total 66 75 88.0


line stmt bran cond sub pod time code
1             package Alien::Build::Plugin::Extract::Negotiate;
2              
3 4     4   1414 use strict;
  4         9  
  4         127  
4 4     4   23 use warnings;
  4         12  
  4         108  
5 4     4   79 use 5.008004;
  4         19  
6 4     4   454 use Alien::Build::Plugin;
  4         10  
  4         28  
7 4     4   1100 use Alien::Build::Plugin::Extract::ArchiveTar;
  4         12  
  4         45  
8 4     4   1742 use Alien::Build::Plugin::Extract::ArchiveZip;
  4         10  
  4         31  
9 4     4   1082 use Alien::Build::Plugin::Extract::CommandLine;
  4         18  
  4         52  
10 4     4   1604 use Alien::Build::Plugin::Extract::Directory;
  4         12  
  4         27  
11              
12             # ABSTRACT: Extraction negotiation plugin
13             our $VERSION = '2.46'; # VERSION
14              
15              
16             has '+format' => 'tar';
17              
18             sub init
19             {
20 7     7 1 19 my($self, $meta) = @_;
21              
22 7         23 my $format = $self->format;
23 7 50       27 $format = 'tar.gz' if $format eq 'tgz';
24 7 50       20 $format = 'tar.bz2' if $format eq 'tbz';
25 7 50       19 $format = 'tar.xz' if $format eq 'txz';
26              
27 7         19 my $plugin = $self->pick($format);
28 7         35 $meta->apply_plugin($plugin, format => $format);
29 7         18 $self;
30             }
31              
32              
33             sub pick
34             {
35 19     19 1 24870 my(undef, $format) = @_;
36              
37 19 100 33     183 if($format =~ /^tar(\.(gz|bz2))?$/)
    100          
    50          
    50          
38             {
39 12 100       98 if(Alien::Build::Plugin::Extract::ArchiveTar->available($format))
40             {
41 11         485 return 'Extract::ArchiveTar';
42             }
43             else
44             {
45 1         335 return 'Extract::CommandLine';
46             }
47             }
48             elsif($format eq 'zip')
49             {
50             # Archive::Zip is not that reliable. But if it is already installed it is probably working
51 5 100       44 if(Alien::Build::Plugin::Extract::ArchiveZip->available($format))
52             {
53 2         25 return 'Extract::ArchiveZip';
54             }
55              
56             # If it isn't available, then use the command-line unzip. Alien::unzip will be used
57             # as necessary in environments where it isn't already installed.
58             else
59             {
60 3         38 return 'Extract::CommandLine';
61             }
62             }
63             elsif($format eq 'tar.xz' || $format eq 'tar.Z')
64             {
65 0         0 return 'Extract::CommandLine';
66             }
67             elsif($format eq 'd')
68             {
69 2         13 return 'Extract::Directory';
70             }
71             else
72             {
73 0           die "do not know how to handle format: $format";
74             }
75             }
76              
77             1;
78              
79             __END__