TaskPipe/PathSettings.pm

filter: Statementstmt 89.0% 81 / 91 Branchbran 60.7% 17 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 95.6% 22 / 23 Podpod 0.0% 0 / 6 totaltotal 81.0% 120 / 148 CC 15 SCAR 8.0
CC
15
Cov
82%
project_dir
3.2
__ANON__
3.2
filename
3.2
CRAP 2.2
« TaskPipe/Task/ModuleMap.pm ↑ Summary TaskPipe/UserAgentManager_ProxyNet_TOR.pm »
1 package TaskPipe::PathSettings;
2  
3 42 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 42 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 42 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 42 ▶use TaskPipe::PathSettings::Project;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 42 ▶use TaskPipe::PathSettings::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 42 ▶use TaskPipe::RunInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 42 ▶use File::Save::Home;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 42 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 42 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 42 with 'MooseX::ConfigCascade';
14 42 with 'TaskPipe::Role::MooseType_ScopeMode';
15  
16 has run_info => (is => 'ro', isa => 'TaskPipe::RunInfo', default => sub{
17 7881 ▶ TaskPipe::RunInfo->new;
Subroutine __ANON__: called CC=1 SCAR=0.0
18 42 });
19  
20 has scope => (is => 'rw', isa => 'ScopeMode', default => sub {
21 2403 ▶ $_[0]->run_info->scope;
Subroutine __ANON__: called CC=1 SCAR=0.0
22 42 });
23  
24 has project => (is => 'rw', isa => 'TaskPipe::PathSettings::Project', default => sub{
25 7881 ▶ TaskPipe::PathSettings::Project->new;
Subroutine __ANON__: called CC=1 SCAR=0.0
26 42 });
27 has global => (is => 'rw', isa => 'TaskPipe::PathSettings::Global', default => sub{
28 7807 ▶ TaskPipe::PathSettings::Global->new
Subroutine __ANON__: called CC=1 SCAR=0.0
29 42 });
30 has project_name => (is => 'rw', isa => 'Str', lazy => 1, default => sub{
31 1169 ▶ return $_[0]->global->project;
Subroutine __ANON__: called CC=1 SCAR=0.0
32 42 });
33 has root_dir => (is => 'ro', isa => 'Str', lazy => 1, default => sub{
34 1773 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=2 SCAR=11.6
35  
36 1773 ▶ return $self->global->root_dir if +$self->global->root_dir;
Branch: 1 branch
BranchTrueFalseTotal
if $self->global->root_dir 1773 0 1773
37  
38 0 my $home_fp = $self->home_filepath;
39 #open my $fh, "<", $home_fp or confess "Could not open $home_fp: $!";
40 #my $root_dir = <$fh>;
41 0 my $root_dir = read_file( $home_fp );
42 0 $root_dir =~ s/^\s*//s;
43 0 $root_dir =~ s/\s*$//s;
44  
45 #close $fh or die "close file $home_fp failed: $!";
46 0 return $root_dir;
47 42 });
48  
49 42 has _no_project_err => (is => 'ro', isa => 'Str', default => "[B<Could not determine the name of the project to use. Did you forget to include> C<--project> B<on the command line? Alternatively, specify a default project in the TaskPipe::PathSettings::Global section in your config:>
50  
51 project: myproject
52  
53 ]");
54  
55  
56 sub path{
57 4493 ▶ my ($self,$dir_name,@frags) = @_;
Subroutine path: called CC=3 SCAR=11.0
Pod undocumented
58  
59 4493 my $path;
60  
61 4493 ▶ if ( $self->scope eq 'global' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->scope eq 'global') { } 2683 1810 4493
62 2683 $path = $self->_global_path($dir_name,@frags);
63 } else {
64 1810 $path = $self->_project_path($dir_name,@frags);
65 }
66  
67 4493 ▶ $path = File::Spec->catdir($path,@frags) if @frags;
Branch: 1 branch
BranchTrueFalseTotal
if @frags 2729 1764 4493
68 4493 return $path;
69 }
70  
71  
72 sub _global_path{
73 2683 ▶ my ($self, $dir_name, @frags) = @_;
Subroutine _global_path: called CC=2 SCAR=7.0
74  
75 2683 my $method = 'global_'.$dir_name.'_dir';
76  
77 2683 ▶ confess "A directory named '$dir_name' has not been defined" unless $self->global->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->global->can($method) 0 2683 2683
78 2683 return +File::Spec->catdir(
79 $self->root_dir,
80 $self->global->global_dir,
81 $self->global->$method
82 );
83 }
84  
85  
86 sub _project_path{
87 1810 ▶ my ($self, $dir_name, @frags) = @_;
Subroutine _project_path: called CC=3 SCAR=11.0
88
89 1810 ▶ if ( $dir_name eq 'conf' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dir_name eq 'conf') { } 919 891 1810
90  
91 919 return +$self->project_conf_dir;
92  
93 } else {
94  
95 891 my $method = $dir_name.'_dir';
96 891 ▶ confess "A directory named '$dir_name' has not been defined" unless $self->project->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->project->can($method) 0 891 891
97  
98 891 return +File::Spec->catdir(
99 $self->project_dir,
100 $self->project->$method
101 );
102 }
103 }
104
105  
106  
107 sub project_root{
108 5458 ▶ my ($self) = @_;
Subroutine project_root: called CC=3 SCAR=11.4
Pod undocumented
109  
110 5458 ▶ confess "No root_dir" unless $self->root_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->root_dir 0 5458 5458
111 5458 ▶ confess "No project_dir" unless $self->global->project_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->global->project_dir 0 5458 5458
112  
113 5458 return +File::Spec->catdir(
114 $self->root_dir,
115 $self->global->project_dir
116 );
117 }
118  
119  
120  
121 sub project_dir{
122 2729 ▶ my ($self) = @_;
Subroutine project_dir: called CC=3 SCAR=11.8
Pod undocumented
123  
124 2729 my $project_root = $self->project_root;
125 2729 ▶ confess "No project_root" unless $project_root;
Branch: 1 branch
BranchTrueFalseTotal
unless $project_root 0 2729 2729
126  
127 2729 ▶ if ( ! $self->global->project ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->global->project) 0 2729 2729
128 0 confess +$self->_no_project_err;
129 }
130  
131 2729 return +File::Spec->catdir(
132 $self->project_root,
133 $self->global->project
134 );
135 }
136  
137  
138  
139  
140 sub project_conf_dir{
141 919 ▶ my ($self) = @_;
Subroutine project_conf_dir: called CC=3 SCAR=11.4
Pod undocumented
142  
143 919 ▶ confess "No project dir" unless $self->project_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->project_dir 0 919 919
144 919 ▶ confess "No conf_dir" unless $self->global->conf_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->global->conf_dir 0 919 919
145  
146 919 return +File::Spec->catdir(
147 $self->project_dir,
148 $self->global->conf_dir
149 );
150 }
151  
152  
153  
154 sub filename{
155 882 ▶ my ($self,$file_label) = @_;
Subroutine filename: called CC=3 SCAR=11.6
Pod undocumented
156  
157 882 my $method;
158 882 ▶ if ( $self->scope eq 'global' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->scope eq 'global') { } 0 882 882
159 0 $method = $file_label.'_conf_filename';
160 } else {
161 882 $method = $file_label.'_filename';
162 }
163  
164 882 ▶ confess "Method $method not found on ".ref( $self->global ) unless $self->global->can( $method );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->global->can($method) 0 882 882
165 882 return +$self->global->$method;
166 }
167  
168  
169 sub home_filepath{
170 0 ▶ my ($self) = @_;
Subroutine home_filepath: not called CC=1 SCAR=6.9
Pod undocumented
171  
172 0 my $home_dir = File::Save::Home::get_home_directory();
173 0 return +File::Spec->catdir( $home_dir, $self->global->home_filename );
174 }
175  
176 =head1 NAME
177  
178 TaskPipe::PathSettings - Path settings for TaskPipe
179  
180 =head1 DESCRIPTION
181  
182 It is not recommended to use this module directly. See the general manpages for TaskPipe
183  
184 =head1 AUTHOR
185  
186 Tom Gracey <tomgracey@gmail.com>
187  
188 =head1 COPYRIGHT AND LICENSE
189  
190 Copyright (c) Tom Gracey 2018
191  
192 TaskPipe is free software, licensed under
193  
194 The GNU Public License Version 3
195  
196 =cut
197  
198  
199 42 __PACKAGE__->meta->make_immutable;
200 42 1;
201 __END__
« TaskPipe/Task/ModuleMap.pm ↑ Summary TaskPipe/UserAgentManager_ProxyNet_TOR.pm »