File Coverage

blib/lib/Debian/Snapshot/Binary.pm
Criterion Covered Total %
statement 13 36 36.1
branch 0 18 0.0
condition 0 3 0.0
subroutine 5 8 62.5
pod 1 1 100.0
total 19 66 28.7


line stmt bran cond sub pod time code
1             package Debian::Snapshot::Binary;
2             BEGIN {
3 3     3   81 $Debian::Snapshot::Binary::VERSION = '0.003';
4             }
5             # ABSTRACT: information on a binary package
6              
7 3     3   16 use Any::Moose;
  3         5  
  3         17  
8              
9 3     3   3239 use Debian::Snapshot::File;
  3         13  
  3         116  
10 3     3   25 use File::Spec;
  3         4  
  3         1640  
11              
12             has 'binary_version' => (
13             is => 'ro',
14             isa => 'Str',
15             required => 1,
16             );
17              
18             has 'name' => (
19             is => 'ro',
20             isa => 'Str',
21             required => 1,
22             );
23              
24             has 'package' => (
25             is => 'ro',
26             isa => 'Debian::Snapshot::Package',
27             required => 1,
28             handles => [qw( _service )],
29             );
30              
31             has 'binfiles' => (
32             is => 'ro',
33             isa => 'ArrayRef[HashRef]',
34             lazy => 1,
35             builder => '_binfiles_builder',
36             );
37              
38             sub _binfiles_builder {
39 0     0     my $self = shift;
40              
41 0           my $package = $self->package->package;
42 0           my $version = $self->package->version;
43 0           my $binpkg = $self->name;
44 0           my $binversion = $self->binary_version;
45              
46 0           my $json = $self->_service->_get_json(
47             "/mr/package/$package/$version/binfiles/$binpkg/$binversion?fileinfo=1"
48             );
49              
50 0           my @files = @{ $json->{result} };
  0            
51 0           for (@files) {
52 0           $_->{file} = Debian::Snapshot::File->new(
53             hash => $_->{hash},
54             _fileinfo => $json->{fileinfo}->{ $_->{hash} },
55             _service => $self->_service,
56             );
57             }
58              
59 0           return \@files;
60             }
61              
62             sub _as_string {
63 0     0     my $self = shift;
64 0           return $self->name . "_" . $self->binary_version;
65             }
66              
67             sub download {
68 0     0 1   my ($self, %p) = @_;
69              
70 0 0 0       unless (exists $p{directory} || exists $p{filename}) {
71 0           die "Either 'directory' or 'file' parameter is required.";
72             }
73              
74 0 0         my $architecture = ref($p{architecture}) eq 'Regexp' ? $p{architecture}
75             : qr/^\Q$p{architecture}\E$/;
76              
77 0           my @binfiles = grep $_->{architecture} =~ $architecture, @{ $self->binfiles };
  0            
78 0 0         @binfiles = grep $_->{file}->archive($p{archive_name}), @binfiles if exists $p{archive_name};
79              
80 0 0         die "Found no file for " . $self->_as_string unless @binfiles;
81 0 0         die "Found more than one file for " . $self->_as_string if @binfiles > 1;
82              
83 0 0         return $binfiles[0]->{file}->download(
    0          
    0          
    0          
84             exists $p{archive_name} ? (archive_name => $p{archive_name}) : (),
85             defined $p{directory} ? (directory => $p{directory}) : (),
86             defined $p{filename} ? (filename => $p{filename}) : (),
87             exists $p{overwrite} ? (overwrite => $p{overwrite}) : (),
88             );
89             }
90              
91 3     3   20 no Any::Moose;
  3         4  
  3         16  
92             1;
93              
94              
95              
96             =pod
97              
98             =head1 NAME
99              
100             Debian::Snapshot::Binary - information on a binary package
101              
102             =head1 VERSION
103              
104             version 0.003
105              
106             =head1 ATTRIBUTES
107              
108             =head2 binary_version
109              
110             Version of the binary package.
111              
112             =head2 name
113              
114             Name of the binary package.
115              
116             =head2 package
117              
118             A L object for the
119             associated source package.
120              
121             =head2 binfiles
122              
123             An arrayref of hashrefs with the following keys:
124              
125             =over
126              
127             =item architecture
128              
129             Name of the architecture this package is for. Can be a string or a regular
130             expression.
131              
132             =item hash
133              
134             Hash of this file.
135              
136             =item file
137              
138             A L object for this file.
139              
140             =back
141              
142             =head1 METHODS
143              
144             =head2 download(%params)
145              
146             =over
147              
148             =item architecture
149              
150             (Required.) Name of the architecture to retrieve the .deb file for.
151              
152             =item archive_name
153              
154             (Optional.) Name of the archive to retrieve the package from.
155              
156             =item directory
157              
158             =item filename
159              
160             =item overwrite
161              
162             Passed to L<< Debian::Snapshot::File->download|Debian::Snapshot::File/"download(%params)" >>.
163              
164             =back
165              
166             =head1 SEE ALSO
167              
168             L
169              
170             =head1 AUTHOR
171              
172             Ansgar Burchardt
173              
174             =head1 COPYRIGHT AND LICENSE
175              
176             This software is copyright (c) 2010 by Ansgar Burchardt .
177              
178             This is free software; you can redistribute it and/or modify it under
179             the same terms as the Perl 5 programming language system itself.
180              
181             =cut
182              
183              
184             __END__