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 40 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use TaskPipe::PathSettings::Project;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 40 ▶use TaskPipe::PathSettings::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 40 ▶use TaskPipe::RunInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use File::Save::Home;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 40 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 40 with 'MooseX::ConfigCascade';
14 40 with 'TaskPipe::Role::MooseType_ScopeMode';
15  
16 has run_info => (is => 'ro', isa => 'TaskPipe::RunInfo', default => sub{
17 7395 ▶ TaskPipe::RunInfo->new;
Subroutine __ANON__: called CC=1 SCAR=0.0
18 40 });
19  
20 has scope => (is => 'rw', isa => 'ScopeMode', default => sub {
21 2263 ▶ $_[0]->run_info->scope;
Subroutine __ANON__: called CC=1 SCAR=0.0
22 40 });
23  
24 has project => (is => 'rw', isa => 'TaskPipe::PathSettings::Project', default => sub{
25 7395 ▶ TaskPipe::PathSettings::Project->new;
Subroutine __ANON__: called CC=1 SCAR=0.0
26 40 });
27 has global => (is => 'rw', isa => 'TaskPipe::PathSettings::Global', default => sub{
28 7325 ▶ TaskPipe::PathSettings::Global->new
Subroutine __ANON__: called CC=1 SCAR=0.0
29 40 });
30 has project_name => (is => 'rw', isa => 'Str', lazy => 1, default => sub{
31 1115 ▶ return $_[0]->global->project;
Subroutine __ANON__: called CC=1 SCAR=0.0
32 40 });
33 has root_dir => (is => 'ro', isa => 'Str', lazy => 1, default => sub{
34 1661 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=2 SCAR=11.6
35  
36 1661 ▶ return $self->global->root_dir if +$self->global->root_dir;
Branch: 1 branch
BranchTrueFalseTotal
if $self->global->root_dir 1661 0 1661
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 40 });
48  
49 40 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 4209 ▶ my ($self,$dir_name,@frags) = @_;
Subroutine path: called CC=3 SCAR=11.0
Pod undocumented
58  
59 4209 my $path;
60  
61 4209 ▶ if ( $self->scope eq 'global' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->scope eq 'global') { } 2513 1696 4209
62 2513 $path = $self->_global_path($dir_name,@frags);
63 } else {
64 1696 $path = $self->_project_path($dir_name,@frags);
65 }
66  
67 4209 ▶ $path = File::Spec->catdir($path,@frags) if @frags;
Branch: 1 branch
BranchTrueFalseTotal
if @frags 2557 1652 4209
68 4209 return $path;
69 }
70  
71  
72 sub _global_path{
73 2513 ▶ my ($self, $dir_name, @frags) = @_;
Subroutine _global_path: called CC=2 SCAR=7.0
74  
75 2513 my $method = 'global_'.$dir_name.'_dir';
76  
77 2513 ▶ 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 2513 2513
78 2513 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 1696 ▶ my ($self, $dir_name, @frags) = @_;
Subroutine _project_path: called CC=3 SCAR=11.0
88
89 1696 ▶ if ( $dir_name eq 'conf' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dir_name eq 'conf') { } 861 835 1696
90  
91 861 return +$self->project_conf_dir;
92  
93 } else {
94  
95 835 my $method = $dir_name.'_dir';
96 835 ▶ 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 835 835
97  
98 835 return +File::Spec->catdir(
99 $self->project_dir,
100 $self->project->$method
101 );
102 }
103 }
104
105  
106  
107 sub project_root{
108 5114 ▶ my ($self) = @_;
Subroutine project_root: called CC=3 SCAR=11.4
Pod undocumented
109  
110 5114 ▶ confess "No root_dir" unless $self->root_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->root_dir 0 5114 5114
111 5114 ▶ confess "No project_dir" unless $self->global->project_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->global->project_dir 0 5114 5114
112  
113 5114 return +File::Spec->catdir(
114 $self->root_dir,
115 $self->global->project_dir
116 );
117 }
118  
119  
120  
121 sub project_dir{
122 2557 ▶ my ($self) = @_;
Subroutine project_dir: called CC=3 SCAR=11.8
Pod undocumented
123  
124 2557 my $project_root = $self->project_root;
125 2557 ▶ confess "No project_root" unless $project_root;
Branch: 1 branch
BranchTrueFalseTotal
unless $project_root 0 2557 2557
126  
127 2557 ▶ if ( ! $self->global->project ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->global->project) 0 2557 2557
128 0 confess +$self->_no_project_err;
129 }
130  
131 2557 return +File::Spec->catdir(
132 $self->project_root,
133 $self->global->project
134 );
135 }
136  
137  
138  
139  
140 sub project_conf_dir{
141 861 ▶ my ($self) = @_;
Subroutine project_conf_dir: called CC=3 SCAR=11.4
Pod undocumented
142  
143 861 ▶ confess "No project dir" unless $self->project_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->project_dir 0 861 861
144 861 ▶ confess "No conf_dir" unless $self->global->conf_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->global->conf_dir 0 861 861
145  
146 861 return +File::Spec->catdir(
147 $self->project_dir,
148 $self->global->conf_dir
149 );
150 }
151  
152  
153  
154 sub filename{
155 826 ▶ my ($self,$file_label) = @_;
Subroutine filename: called CC=3 SCAR=11.6
Pod undocumented
156  
157 826 my $method;
158 826 ▶ if ( $self->scope eq 'global' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->scope eq 'global') { } 0 826 826
159 0 $method = $file_label.'_conf_filename';
160 } else {
161 826 $method = $file_label.'_filename';
162 }
163  
164 826 ▶ confess "Method $method not found on ".ref( $self->global ) unless $self->global->can( $method );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->global->can($method) 0 826 826
165 826 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 40 __PACKAGE__->meta->make_immutable;
200 40 1;
201 __END__
« TaskPipe/Task/ModuleMap.pm ↑ Summary TaskPipe/UserAgentManager_ProxyNet_TOR.pm »