blib/lib/HackaMol/X/Roles/ExtensionRole.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 100% 64 / 64 CC 6 SCAR 7.3
CC
6
Cov
100%
capture_sys_command
4.0
map_input
2.0
map_output
2.0
CRAP 2.1
↑ Summary
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
BranchTrueFalseTotal
if $self->has_scratch 1 1 2
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
BranchTrueFalseTotal
if $self->has_scratch 1 1 2
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
BranchTrueFalseTotal
unless (defined $command) 4 1 5
60 4 ▶ return 0 unless $self->has_command;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_command 1 3 4
61 3 $command = $self->command;
62 }
63  
64 4 ▶ local $CWD = $self->scratch if ( $self->has_scratch );
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_scratch 3 1 4
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__
↑ Summary