File Coverage

lib/PortageXS.pm
Criterion Covered Total %
statement 16 94 17.0
branch 0 28 0.0
condition n/a
subroutine 6 12 50.0
pod n/a
total 22 134 16.4


line stmt bran cond sub pod time code
1 5     5   117074 use strict;
  5         11  
  5         162  
2 5     5   28 use warnings;
  5         9  
  5         251  
3              
4             package PortageXS;
5             BEGIN {
6 5     5   325 $PortageXS::AUTHORITY = 'cpan:KENTNL';
7             }
8             {
9             $PortageXS::VERSION = '0.3.1';
10             }
11             # ABSTRACT: Portage abstraction layer for perl
12              
13             # -----------------------------------------------------------------------------
14             #
15             # PortageXS
16             #
17             # author : Christian Hartmann
18             # license : GPL-2
19             # header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS.pm,v 1.14 2008/12/01 19:53:27 ian Exp $
20             #
21             # -----------------------------------------------------------------------------
22             #
23             # This program is free software; you can redistribute it and/or modify it under
24             # the terms of the GNU General Public License as published by the Free Software
25             # Foundation; either version 2 of the License, or (at your option) any later
26             # version.
27             #
28             # -----------------------------------------------------------------------------
29              
30 5     5   4559 use Role::Tiny::With;
  5         28329  
  5         370  
31 5     5   22940 use Path::Tiny qw(path);
  5         94801  
  5         734  
32              
33              
34             with 'PortageXS::Core';
35             with 'PortageXS::System';
36             with 'PortageXS::UI::Console';
37             with 'PortageXS::Useflags';
38              
39 5     5   2365 use PortageXS::Version;
  5         13  
  5         5901  
40              
41             sub portdir {
42 0     0     my $self = shift;
43 0 0         return path($self->{portdir}) if defined $self->{portdir};
44 0           $self->{portdir} = $self->config->getParam('PORTDIR','lastseen');
45 0 0         return path($self->{portdir}) if $self->{portdir};
46 0           my $debug = "";
47 0           for my $file ( @{ $self->config->files }) {
  0            
48 0 0         $debug .= sprintf qq[ * %s : %s \n], $file, ( -e $file ? 'ok' : 'missing' );
49             }
50 0           die "Could not determine PORTDIR from make.conf family: " . $debug;
51             }
52             sub config {
53 0     0     my $self = shift;
54 0 0         return $self->{config} if defined $self->{config};
55 0           return $self->{config} = do {
56 0           require PortageXS::MakeConf;
57 0           return PortageXS::MakeConf->new();
58             };
59             }
60              
61             sub colors {
62 0     0     my $self = shift;
63 0 0         return $self->{colors} if defined $self->{colors};
64 0           return $self->{colors} = do {
65 0           require PortageXS::Colors;
66 0           my $colors = PortageXS::Colors->new();
67 0           my $want_nocolor = $self->config->getParam('NOCOLOR', 'lastseen' );
68              
69 0 0         if ( $want_nocolor eq 'true' ) {
70 0           $colors->disableColors;
71             }
72 0           $colors;
73             };
74             }
75              
76             sub new {
77 0     0     my $self = shift ;
78              
79 0           my $pxs = bless {}, $self;
80 0           require Tie::Hash::Method;
81 0           my %blacklist = (
82             'COLORS' => 'please use pxs->colors ( PortageXS::Colors )',
83             'PORTDIR' => 'please use pxs->portdir'
84             );
85 0           tie %{$pxs}, 'Tie::Hash::Method' => (
86             FETCH => sub {
87 0     0     my ( $self, $key ) = @_;
88 0 0         if ( exists $blacklist{ $_[1] } ) {
89 0           die "$_[1] is gone: " . $blacklist{ $_[1] };
90             }
91 0           $_[0]->base_hash->{ $_[1] };
92             },
93             STORE => sub {
94 0     0     my ( $self, $key, $value ) = @_;
95 0 0         if ( exists $blacklist{ $_[1] } ) {
96 0           die "$_[1] is gone: " . $blacklist{ $_[1] };
97             }
98 0           $_[0]->base_hash->{ $_[1] } = $_[2];
99             }
100 0           );
101 0           $pxs->{'VERSION'} = $PortageXS::VERSION;
102 0           my $prefix = $pxs->{'PREFIX'} = path('/');
103              
104 0           $pxs->{'PKG_DB_DIR'} = $prefix->child('var/db/pkg');
105 0           $pxs->{'PATH_TO_WORLDFILE'} = $prefix->child('var/lib/portage/world');
106 0           $pxs->{'IS_INITIALIZED'} = 1;
107              
108 0           $pxs->{'EXCLUDE_DIRS'}{'.'} = 1;
109 0           $pxs->{'EXCLUDE_DIRS'}{'..'} = 1;
110 0           $pxs->{'EXCLUDE_DIRS'}{'metadata'} = 1;
111 0           $pxs->{'EXCLUDE_DIRS'}{'licenses'} = 1;
112 0           $pxs->{'EXCLUDE_DIRS'}{'eclass'} = 1;
113 0           $pxs->{'EXCLUDE_DIRS'}{'distfiles'} = 1;
114 0           $pxs->{'EXCLUDE_DIRS'}{'profiles'} = 1;
115 0           $pxs->{'EXCLUDE_DIRS'}{'CVS'} = 1;
116 0           $pxs->{'EXCLUDE_DIRS'}{'.cache'} = 1;
117              
118 0           my $etc = $pxs->{'ETC_DIR'} = $prefix->child('etc');
119 0           $pxs->{'PORTAGEXS_ETC_DIR'} = $etc->child('pxs');
120              
121 0           $pxs->{'MAKE_PROFILE_PATHS'} = [
122             $etc->child('make.profile'),
123             $etc->child('portage/make.profile'),
124             ];
125              
126 0           $pxs->{'MAKE_GLOBALS_PATHS'} = [
127             $etc->child('make.globals'),
128             $prefix->child('usr/share/portage/config/make.globals'),
129             ];
130              
131 0           $pxs->{'MAKE_CONF_PATHS'} = [
132             $etc->child('make.conf'),
133             $etc->child('portage/make.conf'),
134             ];
135              
136 0           for my $path ( @{ $pxs->{'MAKE_PROFILE_PATHS'} } ) {
  0            
137 0 0         next unless -e $path;
138 0           $pxs->{'MAKE_PROFILE_PATH'} = $path;
139             }
140 0 0         if ( not defined $pxs->{'MAKE_PROFILE_PATH'} ) {
141 0           die "Error, none of paths for `make.profile` exists." . join q{, }, @{ $pxs->{'MAKE_PROFILE_PATHS'} };
  0            
142             }
143 0           for my $path ( @{ $pxs->{'MAKE_CONF_PATHS'} } ) {
  0            
144 0 0         next unless -e $path;
145 0           $pxs->{'MAKE_CONF_PATH'} = $path;
146             }
147 0 0         if ( not defined $pxs->{'MAKE_CONF_PATH'} ) {
148 0           die "Error, none of paths for `make.conf` exists." . join q{, }, @{ $pxs->{'MAKE_CONF_PATHS'} };
  0            
149             }
150 0           for my $path ( @{ $pxs->{'MAKE_GLOBALS_PATHS'} } ) {
  0            
151 0 0         next unless -e $path;
152 0           $pxs->{'MAKE_GLOBALS_PATH'} = $path;
153             }
154 0 0         if ( not defined $pxs->{'MAKE_GLOBALS_PATH'} ) {
155 0           die "Error, none of paths for `make.globals` exists." . join q{, }, @{ $pxs->{'MAKE_GLOBALS_PATHS'} };
  0            
156             }
157              
158 0           return $pxs;
159             }
160              
161              
162             1;
163              
164             __END__