File Coverage

blib/lib/Pinto/Config.pm
Criterion Covered Total %
statement 40 40 100.0
branch 2 2 100.0
condition n/a
subroutine 13 13 100.0
pod 0 2 0.0
total 55 57 96.4


line stmt bran cond sub pod time code
1             # ABSTRACT: Internal configuration for a Pinto repository
2              
3             package Pinto::Config;
4              
5 52     52   82929 use Moose;
  52         396224  
  52         512  
6 52     52   350694 use MooseX::StrictConstructor;
  52         25156  
  52         477  
7 52     52   176587 use MooseX::Types::Moose qw(Str Bool Int ArrayRef);
  52         47411  
  52         549  
8 52     52   266506 use MooseX::MarkAsMethods ( autoclean => 1 );
  52         7983  
  52         443  
9 52     52   228058 use MooseX::Configuration;
  52         39796  
  52         208  
10 52     52   10536916 use MooseX::Aliases;
  52         60225  
  52         194  
11              
12 52     52   2276121 use URI;
  52         145  
  52         1821  
13              
14 52     52   703 use Pinto::Constants qw(@PINTO_DEFAULT_SOURCE_URIS);
  52         114  
  52         6243  
15 52     52   1041 use Pinto::Types qw(Dir File Username PerlVersion);
  52         110  
  52         830  
16 52     52   379971 use Pinto::Util qw(current_username current_time_offset);
  52         158  
  52         46763  
17              
18             #------------------------------------------------------------------------------
19              
20             our $VERSION = '0.14'; # VERSION
21              
22             #------------------------------------------------------------------------------
23             # Moose attributes
24              
25             has root => (
26             is => 'ro',
27             isa => Dir,
28             alias => 'root_dir',
29             required => 1,
30             coerce => 1,
31             );
32              
33             has username => (
34             is => 'ro',
35             isa => Username,
36             default => sub { return current_username },
37             lazy => 1,
38             );
39              
40             has time_offset => (
41             is => 'ro',
42             isa => Int,
43             default => sub { return current_time_offset },
44             lazy => 1,
45             );
46              
47             has stacks_dir => (
48             is => 'ro',
49             isa => Dir,
50             init_arg => undef,
51             default => sub { return $_[0]->root_dir->subdir('stacks') },
52             lazy => 1,
53             );
54              
55             has authors_dir => (
56             is => 'ro',
57             isa => Dir,
58             init_arg => undef,
59             default => sub { return $_[0]->root_dir->subdir('authors') },
60             lazy => 1,
61             );
62              
63             has authors_id_dir => (
64             is => 'ro',
65             isa => Dir,
66             init_arg => undef,
67             default => sub { return $_[0]->authors_dir->subdir('id') },
68             lazy => 1,
69             );
70              
71             has modules_dir => (
72             is => 'ro',
73             isa => Dir,
74             init_arg => undef,
75             default => sub { return $_[0]->root_dir->subdir('modules') },
76             lazy => 1,
77             );
78              
79             has mailrc_file => (
80             is => 'ro',
81             isa => File,
82             init_arg => undef,
83             default => sub { return $_[0]->authors_dir->file('01mailrc.txt.gz') },
84             lazy => 1,
85             );
86              
87             has db_dir => (
88             is => 'ro',
89             isa => Dir,
90             init_arg => undef,
91             default => sub { return $_[0]->pinto_dir->subdir('db') },
92             lazy => 1,
93             );
94              
95             has db_file => (
96             is => 'ro',
97             isa => File,
98             init_arg => undef,
99             default => sub { return $_[0]->db_dir->file('pinto.db') },
100             lazy => 1,
101             );
102              
103             has pinto_dir => (
104             is => 'ro',
105             isa => Dir,
106             init_arg => undef,
107             default => sub { return $_[0]->root_dir->subdir('.pinto') },
108             lazy => 1,
109             );
110              
111             has config_dir => (
112             is => 'ro',
113             isa => Dir,
114             init_arg => undef,
115             default => sub { return $_[0]->pinto_dir->subdir('config') },
116             lazy => 1,
117             );
118              
119             has cache_dir => (
120             is => 'ro',
121             isa => Dir,
122             init_arg => undef,
123             default => sub { return $_[0]->pinto_dir->subdir('cache') },
124             lazy => 1,
125             );
126              
127             has log_dir => (
128             is => 'ro',
129             isa => Dir,
130             init_arg => undef,
131             default => sub { return $_[0]->pinto_dir->subdir('log') },
132             lazy => 1,
133             );
134              
135             has version_file => (
136             is => 'ro',
137             isa => File,
138             init_arg => undef,
139             default => sub { return $_[0]->pinto_dir->file('version') },
140             lazy => 1,
141             );
142              
143             has basename => (
144             is => 'ro',
145             isa => Str,
146             init_arg => undef,
147             default => 'pinto.ini',
148             );
149              
150             #------------------------------------------------------------------------------
151             # Actual configurable attributes
152              
153             has sources => (
154             is => 'ro',
155             isa => Str,
156             key => 'sources',
157             default => "@PINTO_DEFAULT_SOURCE_URIS",
158             documentation => 'URIs of upstream repositories (space delimited)',
159             );
160              
161             has target_perl_version => (
162             is => 'ro',
163             isa => PerlVersion,
164             key => 'target_perl_version',
165             documentation => 'Default target perl version for new stacks',
166             default => $], # Note: $PERL_VERSION is broken on old perls
167             coerce => 1,
168             );
169              
170             has recurse => (
171             is => 'ro',
172             isa => Bool,
173             key => 'recurse',
174             documentation => 'Default recursive behavior',
175             default => 1,
176             );
177              
178             has intermingle => (
179             is => 'ro',
180             isa => Bool,
181             key => 'intermingle',
182             documentation => 'Allow stacks to intermingle distributions',
183             default => 0,
184             );
185              
186             #------------------------------------------------------------------------------
187              
188             sub _build_config_file {
189 319     319   341027 my ($self) = @_;
190              
191 319         8541 my $config_file = $self->config_dir->file( $self->basename );
192              
193 319 100       31919 return -e $config_file ? $config_file : ();
194             }
195              
196             #------------------------------------------------------------------------------
197              
198             sub sources_list {
199 30     30 0 95 my ($self) = @_;
200              
201             # Some folks tend to put quotes around multi-value configuration
202             # parameters, even though they shouldn't. Be kind and remove them.
203 30         712 my $sources = $self->sources;
204 30         130 $sources =~ s/ ['"] //gx;
205              
206 30         195 return map { URI->new($_) } split m{ \s+ }mx, $sources;
  35         526  
207             }
208              
209             #------------------------------------------------------------------------------
210              
211             sub directories {
212 113     113 0 352 my ($self) = @_;
213              
214 113         838 return ( $self->root_dir, $self->config_dir, $self->cache_dir,
215             $self->authors_dir, $self->log_dir, $self->db_dir );
216             }
217              
218             #------------------------------------------------------------------------------
219              
220             __PACKAGE__->meta->make_immutable;
221              
222             #------------------------------------------------------------------------------
223              
224             1;
225              
226             __END__
227              
228             =pod
229              
230             =encoding UTF-8
231              
232             =for :stopwords Jeffrey Ryan Thalhammer
233              
234             =head1 NAME
235              
236             Pinto::Config - Internal configuration for a Pinto repository
237              
238             =head1 VERSION
239              
240             version 0.14
241              
242             =head1 DESCRIPTION
243              
244             This is a private module for internal use only. There is nothing for
245             you to see here (yet).
246              
247             =head1 AUTHOR
248              
249             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
250              
251             =head1 COPYRIGHT AND LICENSE
252              
253             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
254              
255             This is free software; you can redistribute it and/or modify it under
256             the same terms as the Perl 5 programming language system itself.
257              
258             =cut