blib/lib/Gentoo/VDB.pm

filter: Statementstmt 96.0% 24 / 25 Branchbran 50.0% 2 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 89.1% 41 / 46 SCAR 13.9
CC
4
Cov
87%
new
4.4
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« blib/lib/Gentoo/VDB/Portage.pm ↑ Summary Build »
1 3 ▶use 5.006; # our
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Gentoo::VDB;
6  
7 3 our $VERSION = '0.001001';
8  
9 # ABSTRACT: Simple API for querying VDB Implementations
10  
11 # AUTHORITY
12  
13 # Note: VDB format is not well defined, and its an implementation
14 # detail of Portage itself, which fortunately is mostly similar to
15 # the implementations in other Portage clients.
16 #
17 # However, there's no requirement that the VDB definition be any
18 # specific way, as the only PMS requirement is that every PMS
19 # implementation *should* have a VDB of some description, but
20 # the definition is up to the implementer.
21 #
22 # Hence, all this design is to make that doable.
23 our $BACKENDS = {
24 'portage' => sub {
25 3 ▶ require Gentoo::VDB::Portage;
Subroutine __ANON__: called CC=1 SCAR=0.0
26 3 return 'Gentoo::VDB::Portage';
27 },
28 3 };
29  
30 sub new {
31 3 ▶ my ( $self, @args ) = @_;
Subroutine new: called CC=4 SCAR=14.8
Pod documented
32 3 ▶ my $config = { ref $args[0] ? %{ $args[0] } : @args };
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] ? : 0 3 3
33 3 ▶ my $backend_name = delete $config->{backend} || 'portage';
Condition50%1/2
delete $config->{'backend'} || 'portage'
l!l
03
MC/DC0%0/1
delete $config->{'backend'} || 'portage'
delete $config->{'backend'}
Truth table50%1/2
A
A= delete $config->{'backend'}
Aresult
11
00
34 die "Unknown backend $backend_name"
35 3 ▶ unless exists $BACKENDS->{$backend_name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Gentoo::VDB::BACKENDS->{$backend_name} 0 3 3
36 3 my $backend_module = $BACKENDS->{$backend_name}->();
37 3 my $backend = $backend_module->new($config);
38 3 return bless { backend => $backend, config => $config }, $self;
39 }
40  
41 # ->categories() -> list of CAT
42 6 ▶sub categories { $_[0]->{backend}->categories( @_[ 1 .. $#_ ] ) }
Subroutine categories: called CC=1 SCAR=0.0
Pod documented
43  
44 # ->packages() -> list of CAT/PN-V
45 # ->packages({ in => 'dev-perl' }) -> list of CAT/PN-V in dev-perl/
46 8 ▶sub packages { $_[0]->{backend}->packages( @_[ 1 .. $#_ ] ) }
Subroutine packages: called CC=1 SCAR=0.0
Pod documented
47  
48 # ->properties({ for => 'cat/pn-v' }) -> list of HASH
49 1 ▶sub properties { $_[0]->{backend}->properties( @_[ 1 .. $#_ ] ) }
Subroutine properties: called CC=1 SCAR=0.0
Pod documented
50  
51 # ->get_property({ for => 'cat/pn-v', property => 'propname' }) -> HASH
52 32 ▶sub get_property { $_[0]->{backend}->get_property( @_[ 1 .. $#_ ] ) }
Subroutine get_property: called CC=1 SCAR=0.0
Pod documented
53  
54 3 1;
55  
56 =head1 NAME
57  
58 Gentoo::VDB - Simple API for querying Gentoo's installed-package database
59  
60 =head1 SYNOPSIS
61  
62 use Gentoo::VDB;
63 my $vdb = Gentoo::VDB->new();
64  
65 my (@categories) = $vdb->categories;
66 ## Note: next line is slow
67 my (@packages) = $vdb->packages;
68 ## Much faster
69 my (@packages) = $vdb->packages({ in => 'dev-perl' });
70  
71 =head1 METHODS
72  
73 =head2 C<new>
74  
75 my $instance = Gentoo::VDB->new(\%ARGS);
76  
77 =head2 C<categories>
78  
79 Returns a list of single-token category names that are
80 valid.
81  
82 my (@categories) = $vdb->categories;
83  
84 Note: Categories that have no definite installed
85 packages are omitted, even if their dirs are present.
86  
87 This is mostly because this is the only way to disambiguate between
88 a temporary directory and a category.
89  
90 It is mostly equivalent to
91  
92 find /var/db/pkg \
93 -maxdepth 1 \
94 -mindepth 1 \
95 -not -empty \
96 -printf '%f\n'
97  
98 And should be similarly performant.
99  
100 =head2 C<packages>
101  
102 Returns a list of valid packages in C<CAT/PN-VERSION> form.
103  
104 my ( @packages ) = $vdb->packages();
105 # Show only packages in dev-perl, much faster
106 my ( @packages ) = $vdb->packages({ in => 'dev-perl' });
107  
108 This is mostly equivalent to:
109  
110 find /var/db/pkg \
111 -maxdepth 2 \
112 -mindepth 2 \
113 -not -empty \
114 -printf '%p\n' | \
115 sed -r 's|^.*/([^/]+)/([^/]+)$|\1/\2|'
116 or
117  
118 find /var/db/pkg/dev-perl \
119 -maxdepth 1 \
120 -mindepth 1 \
121 -not -empty \
122 -printf '%p\n' | \
123 sed -r 's|^.*/([^/]+)/([^/]+)$|\1/\2|'
124  
125 And should be similarly performant.
126  
127 =head2 C<properties>
128  
129 Returns a list of hash entries describing properties of the given C<CAT/PN-VERSION>
130  
131 my ( @properties ) = $vdb->properties({ for => 'dev-lang/perl-5.22.1-r1' });
132  
133 A property contains:
134  
135 {
136 property => .... # the name of the property ( backend specific )
137 label => .... # usually the same as 'property' but is defined by
138 # Gentoo::VDB, some special cases like
139 # 'special:source_ebuild' and 'unknown:' . $property
140 # exist.
141 type => .... # Gentoo::VDB specific hint for decoding the
142 # data.
143 for => .... # CAT/PN-V entry
144  
145 # Selectively ...
146 content => # For "generic" types like "file", this is generally
147 # a MIME type for the undelying decoded data.
148 # ie: No VDB Specific decoding hint, just amorphous
149 # blob of bytes that have to be handled thusly
150 # eg: text/plain, application/octet-stream
151  
152 encoding => # if the data has some sort of protocol encoding,
153 # for instance, a bzip encoded text source
154 # this will be populated respectively, eg:
155 # application/x-bzip2
156 }
157  
158 A given record may overlap with another record in part, eg: One "property"
159 may yield 2 different hashes with different labels and types.
160  
161 But this is just an idea at this stage, and there's no implementation behind it.
162  
163 Mostly pertinent for large objects like `environment.bz2` that can yield additional
164 metadata.
165  
166 =head2 C<get_property>
167  
168 Fetch a given property as a string blob
169  
170 my $prop = $vdb->get_property({ for => 'dev-lang/perl-5.22.1-r1', property => 'BackendName' });
171  
172 =head1 AUTHOR
173  
174 Kent Fredric <kentnl@cpan.org>
175  
176 =head1 LICENSE
177  
178 This software is copyright (c) 2016 by Kent Fredric.
179  
180 This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
181  
182 =cut
« blib/lib/Gentoo/VDB/Portage.pm ↑ Summary Build »