File Coverage

blib/lib/Debian/Snapshot/Package.pm
Criterion Covered Total %
statement 10 37 27.0
branch 0 4 0.0
condition n/a
subroutine 4 8 50.0
pod 3 3 100.0
total 17 52 32.6


line stmt bran cond sub pod time code
1             package Debian::Snapshot::Package;
2             BEGIN {
3 3     3   28567 $Debian::Snapshot::Package::VERSION = '0.003';
4             }
5             # ABSTRACT: information about a source package
6              
7 3     3   1061 use Any::Moose;
  3         58320  
  3         25  
8              
9 3     3   3165 use Debian::Snapshot::Binary;
  3         8  
  3         1704  
10              
11             has 'package' => (
12             is => 'ro',
13             isa => 'Str',
14             required => 1,
15             );
16              
17             has 'version' => (
18             is => 'ro',
19             isa => 'Str',
20             required => 1,
21             );
22              
23             has '_service' => (
24             is => 'ro',
25             isa => 'Debian::Snapshot',
26             required => 1,
27             );
28              
29             has 'srcfiles' => (
30             is => 'ro',
31             isa => 'ArrayRef[Debian::Snapshot::File]',
32             lazy => 1,
33             builder => '_srcfiles_builder',
34             );
35              
36             sub _srcfiles_builder {
37 0     0     my $self = shift;
38 0           my $package = $self->package;
39 0           my $version = $self->version;
40              
41 0           my $json = $self->_service->_get_json("/mr/package/$package/$version/srcfiles?fileinfo=1");
42 0           my @files = map Debian::Snapshot::File->new(
43             hash => $_->{hash},
44             _fileinfo => $json->{fileinfo}->{ $_->{hash} },
45             _service => $self->_service,
46 0           ), @{ $json->{result} };
47              
48 0           return \@files;
49             }
50              
51             sub binaries {
52 0     0 1   my $self = shift;
53              
54 0           my $package = $self->package;
55 0           my $version = $self->version;
56 0           my $json = $self->_service->_get_json("/mr/package/$package/$version/binpackages");
57              
58 0           my @binaries = map $self->binary($_->{name}, $_->{version}), @{ $json->{result} };
  0            
59 0           return \@binaries;
60             }
61              
62             sub binary {
63 0     0 1   my ($self, $name, $binary_version) = @_;
64 0           return Debian::Snapshot::Binary->new(
65             package => $self,
66             name => $name,
67             binary_version => $binary_version,
68             );
69             }
70              
71             sub download {
72 0     0 1   my ($self, %p) = @_;
73 0           my $package = $self->package;
74              
75 0           my $ver = $self->version;
76             # filenames do not include epoch
77 0           $ver =~ s/^[0-9]+://;
78              
79             # upstream tarball does not include Debian revision.
80             # filename has either .orig or the Debian revision followed by a dot.
81 0           $ver =~ s/-([a-zA-Z0-9.+~]*)$//;
82 0           my $rev = $1;
83              
84 0           my @local_files;
85 0           for (@{ $self->srcfiles }) {
  0            
86 0 0         push @local_files, $_->download(
    0          
87             defined $p{archive_name} ? (archive_name => $p{archive_name}) : (),
88             directory => $p{directory},
89             filename => qr/^\Q${package}_${ver}\E(?:\.orig|-\Q$rev.\E)/,
90             exists $p{overwrite} ? (overwrite => $p{overwrite}) : (),
91             );
92             }
93              
94 0           return \@local_files;
95             }
96              
97 3     3   23 no Any::Moose;
  3         5  
  3         19  
98             1;
99              
100              
101              
102             =pod
103              
104             =head1 NAME
105              
106             Debian::Snapshot::Package - information about a source package
107              
108             =head1 VERSION
109              
110             version 0.003
111              
112             =head1 ATTRIBUTES
113              
114             =head2 package
115              
116             Name of the source package.
117              
118             =head2 version
119              
120             Version of the source package.
121              
122             =head2 srcfiles
123              
124             Arrayref containing L objects
125             for the source files of this package.
126              
127             =head1 METHODS
128              
129             =head2 binaries
130              
131             Returns an arrayref of L binary
132             packages associated with this source package.
133              
134             =head2 binary($name, $binary_version)
135              
136             Returns a L object for the
137             binary package C<$name> with the version C<$binary_version>.
138              
139             =head2 download(%params)
140              
141             Download the source package.
142              
143             =over
144              
145             =item archive_name
146              
147             =item overwrite
148              
149             Passed to L<< Debian::Snapshot::File->download|Debian::Snapshot::File/"download(%params)" >>.
150              
151             =item directory
152              
153             (Required.) Downloaded source files will be stored in this directory.
154              
155             =back
156              
157             =head1 SEE ALSO
158              
159             L
160              
161             =head1 AUTHOR
162              
163             Ansgar Burchardt
164              
165             =head1 COPYRIGHT AND LICENSE
166              
167             This software is copyright (c) 2010 by Ansgar Burchardt .
168              
169             This is free software; you can redistribute it and/or modify it under
170             the same terms as the Perl 5 programming language system itself.
171              
172             =cut
173              
174              
175             __END__