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   1591 use strict;
  4         12  
  4         130  
4 4     4   22 use warnings;
  4         8  
  4         130  
5 4     4   78 use 5.008004;
  4         14  
6 4     4   496 use Alien::Build::Plugin;
  4         87  
  4         34  
7 4     4   1175 use Alien::Build::Plugin::Extract::ArchiveTar;
  4         31  
  4         57  
8 4     4   1749 use Alien::Build::Plugin::Extract::ArchiveZip;
  4         14  
  4         36  
9 4     4   1114 use Alien::Build::Plugin::Extract::CommandLine;
  4         11  
  4         53  
10 4     4   1754 use Alien::Build::Plugin::Extract::Directory;
  4         13  
  4         28  
11              
12             # ABSTRACT: Extraction negotiation plugin
13             our $VERSION = '2.45'; # VERSION
14              
15              
16             has '+format' => 'tar';
17              
18             sub init
19             {
20 7     7 1 20 my($self, $meta) = @_;
21              
22 7         23 my $format = $self->format;
23 7 50       26 $format = 'tar.gz' if $format eq 'tgz';
24 7 50       18 $format = 'tar.bz2' if $format eq 'tbz';
25 7 50       29 $format = 'tar.xz' if $format eq 'txz';
26              
27 7         19 my $plugin = $self->pick($format);
28 7         38 $meta->apply_plugin($plugin, format => $format);
29 7         26 $self;
30             }
31              
32              
33             sub pick
34             {
35 19     19 1 29373 my(undef, $format) = @_;
36              
37 19 100 33     214 if($format =~ /^tar(\.(gz|bz2))?$/)
    100          
    50          
    50          
38             {
39 12 100       109 if(Alien::Build::Plugin::Extract::ArchiveTar->available($format))
40             {
41 11         626 return 'Extract::ArchiveTar';
42             }
43             else
44             {
45 1         485 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       49 if(Alien::Build::Plugin::Extract::ArchiveZip->available($format))
52             {
53 2         30 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         52 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         14 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__