File Coverage

blib/lib/App/JESP/Plan.pm
Criterion Covered Total %
statement 19 20 95.0
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 25 27 92.5


line stmt bran cond sub pod time code
1             package App::JESP::Plan;
2             $App::JESP::Plan::VERSION = '0.016';
3 8     8   57 use Moose;
  8         18  
  8         47  
4 8     8   54597 use File::Slurp;
  8         245340  
  8         520  
5              
6 8     8   3504 use App::JESP::Patch;
  8         30  
  8         2649  
7              
8             =head1 NAME
9              
10             App::JESP::Plan - Represents a patching plan
11              
12             =cut
13              
14             has 'jesp' => ( is => 'ro' , isa => 'App::JESP', required => 1, weak_ref => 1);
15              
16             has 'file' => ( is => 'ro', isa => 'Str', required => 1 );
17             has 'patches' => ( is => 'ro' , isa => 'ArrayRef[App::JESP::Patch]', lazy_build => 1 );
18              
19             has 'raw_data' => ( is => 'ro', isa => 'HashRef' , lazy_build => 1);
20              
21             sub _build_raw_data{
22 3     3   7 my ($self) = @_;
23 3         78 my $content = File::Slurp::read_file( $self->file() );
24 3         589 return $self->jesp->json->decode( $content );
25             }
26              
27             sub _build_patches{
28 3     3   10 my ($self) = @_;
29 3 50       98 unless( $self->raw_data()->{patches} ){
30 0         0 die "Missing 'patches' in plan file ".$self->file()."\n";
31             }
32              
33 3         9 my @patches = ();
34 3         5 foreach my $raw_patch ( @{ $self->raw_data()->{patches} } ){
  3         73  
35 11         317 push @patches , App::JESP::Patch->new({
36             %$raw_patch,
37             jesp => $self->jesp()
38             });
39             }
40 3         125 return \@patches;
41             }
42              
43             __PACKAGE__->meta->make_immutable();
44             1;