blib/lib/Parse/Debian/Packages.pm

filter: Statementstmt 76.0% 19 / 25 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 3 / 3 totaltotal 75.0% 30 / 40 CC 5 SCAR 13.2
CC
5
Cov
73%
as_hash
6.0
next
4.0
BEGIN
1.0
CRAP 3.8
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Parse::Debian::Packages;
3 1 our $VERSION = '0.03';
4  
5 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
6 1 my $class = shift;
7 1 my $fh = shift;
8  
9 1 return bless { fh => $fh }, $class;
10 }
11  
12 1 ▶sub next {
Subroutine next: called CC=4 SCAR=13.9
Pod documented
13 1 my $self = shift;
14 1 my $fh = $self->{fh};
15  
16 1 my %parsed;
17 1 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 15 0 15
18 15 ▶ last if /^$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^$/ 1 14 15
19 14 ▶ if (my ($key, $value) = m/^(\S+): (.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = /^(\S+): (.*)/) { } 13 1 14
20 13 $parsed{$key} = $value;
21 }
22 else {
23 1 s/ //;
24 1 s/^\.$//;
25 1 $parsed{body} .= $_;
26 }
27 }
28  
29 1 return %parsed;
30 }
31  
32 0 ▶sub as_hash {
Subroutine as_hash: not called CC=2 SCAR=17.9
Pod documented
33 0 my $class = shift;
34 0 my $parser = $class->new(@_);
35 0 my %hash;
36  
37 0 ▶ while (my %package = $parser->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%package) = $parser->next) 0 0 0
38 0 $hash{ $package{Package} } = \%package;
39 }
40 0 return \%hash;
41 }
42  
43 1 1;
44  
45  
46 =head1 NAME
47  
48 Parse::Debian::Packages - parse the data from a debian Packages.gz
49  
50 =head1 SYNOPSIS
51  
52 use YAML;
53 use IO::File;
54 use Parse::Debian::Packages;
55 my $fh = IO::File->new("Packages");
56  
57 my $parser = Parse::Debian::Packages->new( $fh );
58 while (my %package = $parser->next) {
59 print Dump \%package;
60 }
61  
62 =head1 DESCRIPTION
63  
64 This module parses the Packages files used by the debian package
65 management tools.
66  
67 It presents itself as an iterator. Each call of the ->next method
68 will return the next package found in the file.
69  
70 For laziness, we take a filehandle in to the constructor. Please open
71 the file for us.
72  
73 =head1 METHODS
74  
75 =head2 new( $filehandle )
76  
77 =head2 next
78  
79 Iterate to the next package in the file, returns either a hash
80 containing a package description, or false at end of file.
81  
82 =head2 as_hash( $filehandle )
83  
84 Return all the packages from a filehandle as a hash of hashes.
85  
86 =head1 AUTHOR
87  
88 Richard Clamp <richardc@unixbeard.net> with as_hash implementation by
89 Thomas Klausner.
90  
91 =head1 COPYRIGHT
92  
93 Copyright (C) 2003,2005,2012 Richard Clamp. All Rights Reserved.
94  
95 This module is free software; you can redistribute it and/or modify it
96 under the same terms as Perl itself.
97  
98 =head1 SEE ALSO
99  
100 Module::Packaged
101  
102 =cut
103  
↑ Summary