line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::JESP::Patch; |
2
|
|
|
|
|
|
|
$App::JESP::Patch::VERSION = '0.016'; |
3
|
8
|
|
|
8
|
|
54
|
use Moose; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
63
|
|
4
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
52905
|
use File::Spec; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
3592
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
App::JESP::Patch - A patch |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'jesp' => ( is => 'ro', isa => 'App::JESP', required => 1, weak_ref => 1); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'id' => ( is => 'ro', isa => 'Str', required => 1 ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# config: |
18
|
|
|
|
|
|
|
has 'file' => ( is => 'ro', isa => 'Str' ); |
19
|
|
|
|
|
|
|
has 'sql' => ( is => 'ro', isa => 'Maybe[Str]' , lazy_build => 1 ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Will be the absolute filename of the script |
22
|
|
|
|
|
|
|
has 'script_file' => ( is => 'ro', isa => 'Maybe[Str]', lazy_build => 1); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Slurping stuff from files |
25
|
|
|
|
|
|
|
has 'file_data' => ( is => 'ro' , lazy_build => 1 ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#Transient properties: |
28
|
|
|
|
|
|
|
has 'applied_datetime' => ( is => 'rw', isa => 'Str', required => 0 ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _build_file_data{ |
31
|
4
|
|
|
4
|
|
9
|
my ($self) = @_; |
32
|
4
|
50
|
|
|
|
94
|
unless( $self->file() ){ return }; |
|
0
|
|
|
|
|
0
|
|
33
|
|
|
|
|
|
|
|
34
|
4
|
|
|
|
|
93
|
my $file = $self->_abs_file_name( $self->file() ); |
35
|
|
|
|
|
|
|
|
36
|
4
|
50
|
33
|
|
|
191
|
unless( ( -e $file ) && ( -r $file ) ){ die "Cannot read file '$file'\n"; } |
|
0
|
|
|
|
|
0
|
|
37
|
4
|
|
|
|
|
29
|
return File::Slurp::read_file( $file ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _abs_file_name{ |
41
|
5
|
|
|
5
|
|
16
|
my ($self, $filename) = @_; |
42
|
5
|
50
|
|
|
|
163
|
my $file = |
43
|
|
|
|
|
|
|
File::Spec->file_name_is_absolute( $filename ) ? |
44
|
|
|
|
|
|
|
$filename : |
45
|
|
|
|
|
|
|
File::Spec->catfile( $self->jesp()->home() , $filename); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _build_script_file{ |
49
|
1
|
|
|
1
|
|
3
|
my ($self) = @_; |
50
|
1
|
50
|
|
|
|
25
|
unless( $self->file() ){ return; } |
|
0
|
|
|
|
|
0
|
|
51
|
1
|
|
|
|
|
23
|
my $file = $self->_abs_file_name( $self->file() );# |
52
|
1
|
50
|
|
|
|
26
|
unless( -r $file ){ |
53
|
0
|
|
|
|
|
0
|
confess("File '$file' is not readable (or there)"); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
# A script is executable |
56
|
1
|
50
|
|
|
|
17
|
if( -x $file ){ |
57
|
1
|
|
|
|
|
34
|
return $file; |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
0
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _build_sql{ |
63
|
5
|
|
|
5
|
|
61
|
my ($self) = @_; |
64
|
5
|
100
|
|
|
|
137
|
unless ( $self->file() =~ /\.sql$/ ){ |
65
|
1
|
|
|
|
|
23
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
4
|
|
|
|
|
115
|
return $self->file_data(); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
71
|
|
|
|
|
|
|
1; |