File Coverage

blib/lib/PkgForge/Source/SRPM.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package PkgForge::Source::SRPM; # -*-perl-*-
2 3     3   67020 use strict;
  3         7  
  3         126  
3 3     3   18 use warnings;
  3         13  
  3         146  
4              
5             # $Id: SRPM.pm.in 15901 2011-02-16 16:05:28Z squinney@INF.ED.AC.UK $
6             # $Source:$
7             # $Revision: 15901 $
8             # $HeadURL: https://svn.lcfg.org/svn/source/tags/PkgForge/PkgForge_1_4_8/lib/PkgForge/Source/SRPM.pm.in $
9             # $Date: 2011-02-16 16:05:28 +0000 (Wed, 16 Feb 2011) $
10              
11             our $VERSION = '1.4.8';
12              
13 3     3   2901 use Moose;
  0            
  0            
14              
15             with 'PkgForge::Source';
16              
17             use overload q{""} => sub { shift->fullpath };
18              
19             no Moose;
20             __PACKAGE__->meta->make_immutable;
21              
22             sub validate {
23             my ( $self, $file ) = @_;
24              
25             $file ||= $self->fullpath;
26              
27             if ( $file !~ m/\.src\.rpm$/ ) {
28             die "The SRPM file name must end with .src.rpm\n";
29             }
30              
31             if ( !-f $file ) {
32             die "The SRPM file '$file' does not exist\n";
33             }
34              
35             require RPM2;
36              
37             my $hdr = eval { RPM2->open_package($file) };
38             if ( !$hdr || $@ || !$hdr->is_source_package ) {
39             die "The file '$file' is not an SRPM\n";
40             }
41             if ( !grep { m/\.spec$/ } $hdr->files ) {
42             die "The SRPM '$file' does not contain a file which matches '*.spec'\n";
43             }
44              
45             return 1;
46             }
47              
48             1;
49             __END__
50              
51             =head1 NAME
52              
53             PkgForge::Source::SRPM - A source RPM class for the LCFG Package Forge
54              
55             =head1 VERSION
56              
57             This documentation refers to PkgForge::Source::SRPM version 1.4.8
58              
59             =head1 SYNOPSIS
60              
61             use PkgForge::Source::SRPM;
62              
63             my $pkg = PkgForge::Source::SRPM->new( file => "foo-1-2.src.rpm" );
64              
65             my $ok = eval { $pkg->validate() };
66              
67             if ( !$ok || $@ ) {
68             warn "$pkg failed to validate: $@\n";
69             }
70              
71             =head1 DESCRIPTION
72              
73             This module provides a representation of a source RPM package which is
74             used by the LCFG Package Forge software suite.
75              
76             =head1 ATTRIBUTES
77              
78             These attributes all come from the interface which this module
79             implements, there are no overrides.
80              
81             =over 4
82              
83             =item basedir
84              
85             This is the directory in which the source package can be found. If
86             none is given then it defaults to the current directory. The directory
87             must exist.
88              
89             =item file
90              
91             This is the file name of the source package, this attribute is
92             required when creating new objects. The file must exist.
93              
94             =item sha1sum
95              
96             This is the SHA1 checksum of the source package. It will be calculated
97             the first time the attribute is queried.
98              
99             =item type
100              
101             This is a string representing the type of the source package. It is
102             the final part of the name of the module which implements this
103             role. For example, for "PkgForge::Source::SRPM" the type is
104             "SRPM".
105              
106             =back
107              
108             =head1 SUBROUTINES/METHODS
109              
110             =head2 Class Methods
111              
112             =item PkgForge::Source::SRPM->can_handle($file)
113              
114             This class method takes the path to a source file. It returns true or
115             false based on whether or not the module can handle that type of
116             source file. It uses the C<validate> method to do the working of
117             checking the source package. Note that under normal circumstances
118             (i.e. when checking the source package validity) this method must not
119             die.
120              
121             =back
122              
123             =head2 Instance Methods
124              
125             =over 4
126              
127             =item gen_sha1sum
128              
129             This method generates the SHA1 digest for the package and returns it
130             in hexadecimal form. The length of the returned string will be 40 and
131             it will only contain characters from this set: '0'..'9' and 'a'..'f'.
132              
133             =item check_sha1sum
134              
135             This will compare the current value of the SHA1 checksum, as stored in
136             the C<sha1sum> attribute, against the value found by running
137             C<gen_sha1sum> on the package. It returns a boolean value reflecting
138             whether they match.
139              
140             =item validate($file)
141              
142             This does the following validity checks:
143              
144             =over
145              
146             =item The file must exist.
147              
148             =item The file must have the '.src.rpm' suffix.
149              
150             =item It must be a proper source RPM.
151              
152             =item It must contain a specfile with the '.spec' suffix.
153              
154             =back
155              
156             If all tests pass then a true value is returned, otherwise the method
157             will die with an appropriate message for the failed test. You will
158             need the L<RPM2> module for this method to work. It will take either a
159             file name as an argument or use the C<fullpath> method.
160              
161             =back
162              
163             =head1 DEPENDENCIES
164              
165             This module is powered by L<Moose>. It is based on
166             L<PkgForge::Source>. It requires L<RPM2> to validate an SRPM.
167              
168             =head1 SEE ALSO
169              
170             L<PkgForge>, L<PkgForge::Source>
171              
172             =head1 PLATFORMS
173              
174             This is the list of platforms on which we have tested this
175             software. We expect this software to work on any Unix-like platform
176             which is supported by Perl.
177              
178             ScientificLinux5, Fedora13
179              
180             =head1 BUGS AND LIMITATIONS
181              
182             Please report any bugs or problems (or praise!) to bugs@lcfg.org,
183             feedback and patches are also always very welcome.
184              
185             =head1 AUTHOR
186              
187             Stephen Quinney <squinney@inf.ed.ac.uk>
188              
189             =head1 LICENSE AND COPYRIGHT
190              
191             Copyright (C) 2010 University of Edinburgh. All rights reserved.
192              
193             This library is free software; you can redistribute it and/or modify
194             it under the terms of the GPL, version 2 or later.
195              
196             =cut