| 1 | # ABSTRACT: Internal configuration for a Pinto repository | ||||||||||
| 2 | |||||||||||
| 3 | package Pinto::Config; | ||||||||||
| 4 | |||||||||||
| 5 | 59 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 59 | ▶ | use MooseX::StrictConstructor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 59 | ▶ | use MooseX::Types::Moose qw(Str Bool Int ArrayRef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 59 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 59 | ▶ | use MooseX::Configuration; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 59 | ▶ | use MooseX::Aliases; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 59 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 59 | ▶ | use Pinto::Constants qw(@PINTO_DEFAULT_SOURCE_URIS); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 59 | ▶ | use Pinto::Types qw(Dir File Username PerlVersion); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 59 | ▶ | use Pinto::Util qw(current_username current_time_offset); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | #------------------------------------------------------------------------------ | ||||||||||
| 19 | |||||||||||
| 20 | 59 | our $VERSION = '0.14'; # VERSION | |||||||||
| 21 | |||||||||||
| 22 | #------------------------------------------------------------------------------ | ||||||||||
| 23 | # Moose attributes | ||||||||||
| 24 | |||||||||||
| 25 | 59 | 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 | 44 | ▶ | default => sub { return current_username }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 59 | lazy => 1, | |||||||||
| 38 | ); | ||||||||||
| 39 | |||||||||||
| 40 | has time_offset => ( | ||||||||||
| 41 | is => 'ro', | ||||||||||
| 42 | isa => Int, | ||||||||||
| 43 | 54 | ▶ | default => sub { return current_time_offset }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 44 | 59 | lazy => 1, | |||||||||
| 45 | ); | ||||||||||
| 46 | |||||||||||
| 47 | has stacks_dir => ( | ||||||||||
| 48 | is => 'ro', | ||||||||||
| 49 | isa => Dir, | ||||||||||
| 50 | init_arg => undef, | ||||||||||
| 51 | 88 | ▶ | default => sub { return $_[0]->root_dir->subdir('stacks') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 52 | 59 | lazy => 1, | |||||||||
| 53 | ); | ||||||||||
| 54 | |||||||||||
| 55 | has authors_dir => ( | ||||||||||
| 56 | is => 'ro', | ||||||||||
| 57 | isa => Dir, | ||||||||||
| 58 | init_arg => undef, | ||||||||||
| 59 | 284 | ▶ | default => sub { return $_[0]->root_dir->subdir('authors') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 60 | 59 | lazy => 1, | |||||||||
| 61 | ); | ||||||||||
| 62 | |||||||||||
| 63 | has authors_id_dir => ( | ||||||||||
| 64 | is => 'ro', | ||||||||||
| 65 | isa => Dir, | ||||||||||
| 66 | init_arg => undef, | ||||||||||
| 67 | 45 | ▶ | default => sub { return $_[0]->authors_dir->subdir('id') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 68 | 59 | lazy => 1, | |||||||||
| 69 | ); | ||||||||||
| 70 | |||||||||||
| 71 | has modules_dir => ( | ||||||||||
| 72 | is => 'ro', | ||||||||||
| 73 | isa => Dir, | ||||||||||
| 74 | init_arg => undef, | ||||||||||
| 75 | 78 | ▶ | default => sub { return $_[0]->root_dir->subdir('modules') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 76 | 59 | lazy => 1, | |||||||||
| 77 | ); | ||||||||||
| 78 | |||||||||||
| 79 | has mailrc_file => ( | ||||||||||
| 80 | is => 'ro', | ||||||||||
| 81 | isa => File, | ||||||||||
| 82 | init_arg => undef, | ||||||||||
| 83 | 70 | ▶ | default => sub { return $_[0]->authors_dir->file('01mailrc.txt.gz') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 84 | 59 | lazy => 1, | |||||||||
| 85 | ); | ||||||||||
| 86 | |||||||||||
| 87 | has db_dir => ( | ||||||||||
| 88 | is => 'ro', | ||||||||||
| 89 | isa => Dir, | ||||||||||
| 90 | init_arg => undef, | ||||||||||
| 91 | 288 | ▶ | default => sub { return $_[0]->pinto_dir->subdir('db') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 92 | 59 | lazy => 1, | |||||||||
| 93 | ); | ||||||||||
| 94 | |||||||||||
| 95 | has db_file => ( | ||||||||||
| 96 | is => 'ro', | ||||||||||
| 97 | isa => File, | ||||||||||
| 98 | init_arg => undef, | ||||||||||
| 99 | 218 | ▶ | default => sub { return $_[0]->db_dir->file('pinto.db') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 100 | 59 | lazy => 1, | |||||||||
| 101 | ); | ||||||||||
| 102 | |||||||||||
| 103 | has pinto_dir => ( | ||||||||||
| 104 | is => 'ro', | ||||||||||
| 105 | isa => Dir, | ||||||||||
| 106 | init_arg => undef, | ||||||||||
| 107 | 430 | ▶ | default => sub { return $_[0]->root_dir->subdir('.pinto') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 108 | 59 | lazy => 1, | |||||||||
| 109 | ); | ||||||||||
| 110 | |||||||||||
| 111 | has config_dir => ( | ||||||||||
| 112 | is => 'ro', | ||||||||||
| 113 | isa => Dir, | ||||||||||
| 114 | init_arg => undef, | ||||||||||
| 115 | 262 | ▶ | default => sub { return $_[0]->pinto_dir->subdir('config') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 116 | 59 | lazy => 1, | |||||||||
| 117 | ); | ||||||||||
| 118 | |||||||||||
| 119 | has cache_dir => ( | ||||||||||
| 120 | is => 'ro', | ||||||||||
| 121 | isa => Dir, | ||||||||||
| 122 | init_arg => undef, | ||||||||||
| 123 | 71 | ▶ | default => sub { return $_[0]->pinto_dir->subdir('cache') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 124 | 59 | lazy => 1, | |||||||||
| 125 | ); | ||||||||||
| 126 | |||||||||||
| 127 | has log_dir => ( | ||||||||||
| 128 | is => 'ro', | ||||||||||
| 129 | isa => Dir, | ||||||||||
| 130 | init_arg => undef, | ||||||||||
| 131 | 70 | ▶ | default => sub { return $_[0]->pinto_dir->subdir('log') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 132 | 59 | lazy => 1, | |||||||||
| 133 | ); | ||||||||||
| 134 | |||||||||||
| 135 | has version_file => ( | ||||||||||
| 136 | is => 'ro', | ||||||||||
| 137 | isa => File, | ||||||||||
| 138 | init_arg => undef, | ||||||||||
| 139 | 201 | ▶ | default => sub { return $_[0]->pinto_dir->file('version') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 140 | 59 | lazy => 1, | |||||||||
| 141 | ); | ||||||||||
| 142 | |||||||||||
| 143 | 59 | 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 | 59 | 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 | 59 | 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 | 59 | has recurse => ( | |||||||||
| 171 | is => 'ro', | ||||||||||
| 172 | isa => Bool, | ||||||||||
| 173 | key => 'recurse', | ||||||||||
| 174 | documentation => 'Default recursive behavior', | ||||||||||
| 175 | default => 1, | ||||||||||
| 176 | ); | ||||||||||
| 177 | |||||||||||
| 178 | 59 | 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 | 192 | ▶ | sub _build_config_file { | ||||||||
|
Subroutine
_build_config_file: called CC=2 SCAR=6.9
| |||||||||||
| 189 | 192 | my ($self) = @_; | |||||||||
| 190 | |||||||||||
| 191 | 192 | my $config_file = $self->config_dir->file( $self->basename ); | |||||||||
| 192 | |||||||||||
| 193 | 192 | ▶ | return -e $config_file ? $config_file : (); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 194 | } | ||||||||||
| 195 | |||||||||||
| 196 | #------------------------------------------------------------------------------ | ||||||||||
| 197 | |||||||||||
| 198 | 3 | ▶ | sub sources_list { | ||||||||
|
Subroutine
sources_list: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 199 | 3 | 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 | 3 | my $sources = $self->sources; | |||||||||
| 204 | 3 | $sources =~ s/ ['"] //gx; | |||||||||
| 205 | |||||||||||
| 206 | 3 | return map { URI->new($_) } split m{ \s+ }mx, $sources; | |||||||||
| 207 | } | ||||||||||
| 208 | |||||||||||
| 209 | #------------------------------------------------------------------------------ | ||||||||||
| 210 | |||||||||||
| 211 | 70 | ▶ | sub directories { | ||||||||
|
Subroutine
directories: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 212 | 70 | my ($self) = @_; | |||||||||
| 213 | |||||||||||
| 214 | 70 | 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 | 59 | __PACKAGE__->meta->make_immutable; | |||||||||
| 221 | |||||||||||
| 222 | #------------------------------------------------------------------------------ | ||||||||||
| 223 | |||||||||||
| 224 | 59 | 1; | |||||||||
| 225 | |||||||||||
| 226 | __END__ | ||||||||||