TaskPipe/Task/ModuleMap.pm

filter: Statementstmt 50.0% 20 / 40 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 41.6% 5 / 12 Podpod 0.0% 0 / 1 totaltotal 45.4% 25 / 55 CC 2 SCAR 8.0
CC
2
Cov
48%
_get_mod_name
6.0
__ANON__
2.0
load_module
2.0
CRAP 2.2
« TaskPipe/SchemaManager.pm ↑ Summary TaskPipe/PathSettings.pm »
1 package TaskPipe::Task::ModuleMap;
2  
3 41 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 41 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 41 ▶use TaskPipe::PathSettings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 41 ▶use Module::Runtime 'require_module';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 41 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 41 with 'MooseX::ConfigCascade';
10  
11 has path_settings => (is => 'ro', isa => 'TaskPipe::PathSettings', default => sub{
12 0 ▶ TaskPipe::PathSettings->new;
Subroutine __ANON__: not called CC=1 SCAR=6.9
13 41 });
14  
15 41 has task_name => (is => 'rw', isa => 'Str');
16  
17  
18 sub load_module{
19 0 ▶ my $self = shift;
Subroutine load_module: not called CC=1 SCAR=6.9
Pod undocumented
20  
21 0 my $mod = $self->_get_mod_name( $self->path_settings->project->task_module_prefix );
22 0 my @err;
23  
24 try {
25  
26 0 ▶ require_module( $mod );
Subroutine __ANON__: not called CC=1 SCAR=6.9
27  
28 } catch {
29
30 0 ▶ push @err, $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 my $tmod = $self->_get_mod_name( 'TaskPipe' );
32
33 try {
34  
35 0 ▶ require_module( $tmod );
Subroutine __ANON__: not called CC=1 SCAR=6.9
36  
37 } catch {
38  
39 0 ▶ push @err, $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 0 confess "Could not load a module for task_name ".$self->task_name." - module missing or broken. Tried to load $mod with result \"$err[0]]\" and $tmod with result \"$err[1]\". \@INC = @INC)";
41  
42 0 };
43 0 $mod = $tmod;
44 0 };
45  
46 0 return $mod;
47
48 }
49  
50  
51  
52 sub _get_mod_name{
53 0 ▶ my ($self,$prefix) = @_;
Subroutine _get_mod_name: not called CC=2 SCAR=17.9
54  
55 0 my $mod = $prefix;
56 0 $mod =~ s/::$//;
57 0 ▶ $mod.= '::' if $mod;
Branch: 1 branch
BranchTrueFalseTotal
if $mod 0 0 0
58 0 $mod.= $self->path_settings->project->task_identifier.$self->task_name;
59  
60 0 return $mod;
61 }
62  
63  
64 =head1 NAME
65  
66 TaskPipe::Task::ModuleMap - map task names to modules
67  
68 =head1 DESCRIPTION
69  
70 Load and return the correct module associated with the task_name. This is used by L<TaskPipe::Task>. It is not recommended to use this module directly.
71  
72 =head1 AUTHOR
73  
74 Tom Gracey <tomgracey@gmail.com>
75  
76 =head1 COPYRIGHT AND LICENSE
77  
78 Copyright (c) Tom Gracey 2018
79  
80 TaskPipe is free software, licensed under
81  
82 The GNU Public License Version 3
83  
84 =cut
85  
86 41 __PACKAGE__->meta->make_immutable;
87  
88 41 1;
« TaskPipe/SchemaManager.pm ↑ Summary TaskPipe/PathSettings.pm »