File Coverage

blib/lib/Alien/Build/Plugin/Decode/DirListing.pm
Criterion Covered Total %
statement 19 29 65.5
branch 0 2 0.0
condition n/a
subroutine 6 7 85.7
pod 1 1 100.0
total 26 39 66.6


line stmt bran cond sub pod time code
1             package Alien::Build::Plugin::Decode::DirListing;
2              
3 2     2   1244 use strict;
  2         5  
  2         67  
4 2     2   12 use warnings;
  2         3  
  2         45  
5 2     2   27 use 5.008004;
  2         7  
6 2     2   357 use Alien::Build::Plugin;
  2         4  
  2         13  
7 2     2   16 use File::Basename ();
  2         3  
  2         624  
8              
9             # ABSTRACT: Plugin to extract links from a directory listing
10             our $VERSION = '2.45'; # VERSION
11              
12              
13             sub init
14             {
15 2     2 1 10 my($self, $meta) = @_;
16              
17 2         6 $meta->add_requires('share' => 'File::Listing' => 0);
18 2         5 $meta->add_requires('share' => 'URI' => 0);
19              
20             $meta->register_hook( decode => sub {
21 0     0   0 my(undef, $res) = @_;
22              
23 0         0 die "do not know how to decode @{[ $res->{type} ]}"
24 0 0       0 unless $res->{type} eq 'dir_listing';
25              
26 0         0 my $base = URI->new($res->{base});
27              
28             return {
29             type => 'list',
30             list => [
31             map {
32 0         0 my($name) = @$_;
33 0         0 my $basename = $name;
34 0         0 $basename =~ s{/$}{};
35 0         0 my %h = (
36             filename => File::Basename::basename($basename),
37             url => URI->new_abs($name, $base)->as_string,
38             );
39 0         0 \%h;
40             } File::Listing::parse_dir($res->{content})
41 0         0 ],
42             };
43 2         14 });
44              
45 2         3 $self;
46             }
47              
48             1;
49              
50             __END__