| 1 | package HackaMol::X::Roles::ExtensionRole; | ||||||||||
| 2 | 2 | $HackaMol::X::Roles::ExtensionRole::VERSION = '0.013'; | |||||||||
| 3 | # ABSTRACT: Role to assist writing HackaMol extensions to external programs | ||||||||||
| 4 | 2 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use Capture::Tiny ':all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use File::chdir; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | with qw(HackaMol::Roles::ExeRole HackaMol::Roles::PathRole); | |||||||||
| 11 | |||||||||||
| 12 | 2 | requires qw(_build_map_in _build_map_out build_command); | |||||||||
| 13 | |||||||||||
| 14 | 2 | has 'mol' => ( | |||||||||
| 15 | is => 'rw', | ||||||||||
| 16 | isa => 'HackaMol::Molecule', | ||||||||||
| 17 | predicate => 'has_mol', | ||||||||||
| 18 | clearer => 'clear_mol', | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 2 | has 'map_in' => ( | |||||||||
| 22 | is => 'ro', | ||||||||||
| 23 | isa => 'CodeRef', | ||||||||||
| 24 | predicate => 'has_map_in', | ||||||||||
| 25 | builder => '_build_map_in', | ||||||||||
| 26 | lazy => 1, | ||||||||||
| 27 | ); | ||||||||||
| 28 | 2 | has 'map_out' => ( | |||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | isa => 'CodeRef', | ||||||||||
| 31 | predicate => 'has_map_out', | ||||||||||
| 32 | builder => '_build_map_out', | ||||||||||
| 33 | lazy => 1, | ||||||||||
| 34 | ); | ||||||||||
| 35 | |||||||||||
| 36 | 2 | ▶ | sub map_input { | ||||||||
|
Subroutine
map_input: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 37 | |||||||||||
| 38 | # pass everything and anything to map_in... i.e. keep @_ in tact | ||||||||||
| 39 | 2 | my ($self) = @_; | |||||||||
| 40 | 2 | ▶ | local $CWD = $self->scratch if ( $self->has_scratch ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 2 | return ( &{ $self->map_in }(@_) ); | |||||||||
| 42 | |||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 2 | ▶ | sub map_output { | ||||||||
|
Subroutine
map_output: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 46 | |||||||||||
| 47 | # pass everything and anything to map_out... i.e. keep @_ in tact | ||||||||||
| 48 | 2 | my ($self) = @_; | |||||||||
| 49 | 2 | ▶ | local $CWD = $self->scratch if ( $self->has_scratch ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 2 | return ( &{ $self->map_out }(@_) ); | |||||||||
| 51 | |||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 5 | ▶ | sub capture_sys_command { | ||||||||
|
Subroutine
capture_sys_command: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 55 | |||||||||||
| 56 | # run it and return all that is captured | ||||||||||
| 57 | 5 | my $self = shift; | |||||||||
| 58 | 5 | my $command = shift; | |||||||||
| 59 | 5 | ▶ | unless ( defined($command) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 4 | ▶ | return 0 unless $self->has_command; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 3 | $command = $self->command; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 4 | ▶ | local $CWD = $self->scratch if ( $self->has_scratch ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 4 | ▶ | my ( $stdout, $stderr, @exit ) = capture { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 66 | 4 | system($command); | |||||||||
| 67 | 4 | }; | |||||||||
| 68 | 4 | return ( $stdout, $stderr, @exit ); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 2 | ▶ | no Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 72 | |||||||||||
| 73 | 2 | 1; | |||||||||
| 74 | |||||||||||
| 75 | __END__ | ||||||||||