StateMigrations/Migration/Routine/PerlCode.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 90 CC 8 SCAR 30.6
CC
8
Cov
0%
_get_routine_coderef
42.0
BUILD
12.0
BEGIN
2.0
CRAP 21.3
1 package DBIx::Class::StateMigrations::Migration::Routine::PerlCode;
2  
3 use strict;
4 use warnings;
5  
6 # ABSTRACT: individual migration for a single version bump
7  
8 use Moo;
9 extends 'DBIx::Class::StateMigrations::Migration::Routine';
10  
11 use Types::Standard qw(:all);
12 use Path::Class 'file';
13  
14 has 'file_path', is => 'ro', isa => Maybe[Str], default => sub { undef };
15 has 'eval_code', is => 'ro', isa => Maybe[Str], default => sub { undef };
16  
17 sub BUILD {
18 my $self = shift;
19 die "Must supply 'file_path' or 'eval_code'" unless ($self->file_path || $self->eval_code);
20 die "Supply either 'file_path' or 'eval_code' - not both" if ($self->file_path && $self->eval_code);
21 }
22  
23 sub _get_routine_coderef {
24 my $self = shift;
25
26 my $coderef;
27
28 if($self->file_path) {
29 my $File = file($self->file_path)->absolute;
30 -f $File or die "Supplied file '".$self->file_path."' not found";
31
32 my $eval = $File->slurp;
33 die "Supplied file '".$self->file_path."' is empty" unless ($eval);
34 $coderef = eval $eval;
35 die "Supplied file '" . $self->file_path . "' did not return a CodeRef" unless (
36 $coderef && ref($coderef)||'' eq 'CODE'
37 );
38 }
39 elsif($self->eval_code) {
40 my $eval = $self->eval_code;
41 $coderef = eval $eval;
42 die "Supplied 'eval_code' did not return a CodeRef" unless (
43 $coderef && ref($coderef)||'' eq 'CODE'
44 );
45 }
46 else {
47 die "No file or eval_code - this is a bug"
48 }
49
50 $coderef
51 }
52  
53  
54  
55 1;
56  
57 __END__