| 1 | package TaskPipe::Task::ModuleMap; | ||||||||||
| 2 | |||||||||||
| 3 | 39 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 39 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 39 | ▶ | use TaskPipe::PathSettings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 39 | ▶ | use Module::Runtime 'require_module'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 39 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 39 | 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 | 39 | }); | |||||||||
| 14 | |||||||||||
| 15 | 39 | 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
| |||||||||||
| 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 | 39 | __PACKAGE__->meta->make_immutable; | |||||||||
| 87 | |||||||||||
| 88 | 39 | 1; | |||||||||