JobControl/Helper/Project/Formular.pm

filter: Statementstmt 35.6% 26 / 73 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 34.7% 8 / 23 Podpod 0.0% 0 / 14 totaltotal 27.4% 34 / 124 CC 6 SCAR 11.5
CC
6
Cov
31%
new
6.0
public
6.0
load
6.0
CRAP 3.1
« JobControl/Dashboard.pm ↑ Summary JobControl/Mojolicious/Plugin/Audit.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4 # vim: set ts=2 sw=2 tw=0:
5 # vim: set expandtab:
6  
7 package Rex::JobControl::Helper::Project::Formular;
8 1 $Rex::JobControl::Helper::Project::Formular::VERSION = '0.18.0';
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Rex::JobControl::Helper::Chdir;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Rex::JobControl::Helper::Project::Job;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
20 0 my $that = shift;
21 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
22 0 my $self = {@_};
23  
24 0 bless( $self, $proto );
25  
26 0 $self->load;
27  
28 0 return $self;
29 }
30  
31 0 ▶sub name { (shift)->{formular_configuration}->{name} }
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
32 0 ▶sub description { (shift)->{formular_configuration}->{description} }
Subroutine description: not called CC=1 SCAR=6.9
Pod undocumented
33  
34 0 ▶sub job {
Subroutine job: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my $self = shift;
36 0 $self->project->get_job( $self->{formular_configuration}->{job} );
37 }
38 0 ▶sub public { (shift)->{formular_configuration}->{public} ? "yes" : "no" }
Subroutine public: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'formular_configuration'}{'public'} ? : 0 0 0
39 0 ▶sub servers { (shift)->{formular_configuration}->{servers} }
Subroutine servers: not called CC=1 SCAR=6.9
Pod undocumented
40 0 ▶sub project { (shift)->{project} }
Subroutine project: not called CC=1 SCAR=6.9
Pod undocumented
41 0 ▶sub directory { (shift)->{directory} }
Subroutine directory: not called CC=1 SCAR=6.9
Pod undocumented
42  
43 0 ▶sub load {
Subroutine load: not called CC=2 SCAR=17.9
Pod undocumented
44 0 my ($self) = @_;
45  
46 0 ▶ if ( -f $self->_config_file() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $self->_config_file) 0 0 0
47 0 $self->{formular_configuration} = YAML::LoadFile( $self->_config_file );
48  
49 my $steps_file = File::Spec->catfile(
50 $self->project->project_path(), "formulars",
51 0 $self->{directory}, "steps.yml"
52 );
53  
54 0 $self->{steps} = YAML::LoadFile($steps_file);
55 }
56 }
57  
58 0 ▶sub _config_file {
Subroutine _config_file: not called CC=1 SCAR=6.9
59 0 my ($self) = @_;
60 return File::Spec->catfile( $self->project->project_path(),
61 0 "formulars", $self->{directory}, "formular.conf.yml" );
62 }
63  
64 0 ▶sub steps {
Subroutine steps: not called CC=2 SCAR=17.9
Pod undocumented
65 0 my ($self) = @_;
66 0 ▶ return $self->{steps}->{formulars} || [];
Condition0%0/2
$self->{'steps'}{'formulars'} || []
l!l
00
MC/DC0%0/1
$self->{'steps'}{'formulars'} || []
$self->{'steps'}{'formulars'}
Truth table0%0/2
A
A= $self->{'steps'}{'formulars'}
Aresult
11
00
67 }
68  
69 0 ▶sub formulars {
Subroutine formulars: not called CC=1 SCAR=6.9
Pod undocumented
70 0 my ($self) = @_;
71 0 return $self->{steps}->{formulars};
72 }
73  
74 0 ▶sub create {
Subroutine create: not called CC=1 SCAR=6.9
Pod undocumented
75 0 my ( $self, %data ) = @_;
76  
77 my $form_path = File::Spec->catdir( $self->project->project_path,
78 0 "formulars", $self->{directory} );
79  
80 0 $self->project->app->log->debug(
81 "Creating new formular $self->{directory} in $form_path.");
82  
83 0 File::Path::make_path($form_path);
84  
85 0 my $steps = $data{steps};
86  
87 0 delete $data{directory};
88 0 delete $data{steps};
89  
90 0 my $form_configuration = {%data};
91  
92 0 YAML::DumpFile( "$form_path/formular.conf.yml", $form_configuration );
93 0 YAML::DumpFile( "$form_path/steps.yml", $steps );
94 }
95  
96 0 ▶sub update {
Subroutine update: not called CC=2 SCAR=17.9
Pod undocumented
97 0 my ( $self, %data ) = @_;
98  
99 my $form_path = File::Spec->catdir( $self->project->project_path,
100 0 "formulars", $self->{directory} );
101  
102 0 $self->project->app->log->debug(
103 "Updating formular $self->{directory} in $form_path.");
104  
105 0 ▶ if ( exists $data{steps} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data{"steps"}) 0 0 0
106 0 YAML::DumpFile( "$form_path/steps.yml", $data{steps} );
107 }
108  
109 0 delete $data{directory};
110 0 delete $data{steps};
111  
112 0 my $form_configuration = {%data};
113 0 YAML::DumpFile( "$form_path/formular.conf.yml", $form_configuration );
114 }
115  
116 0 ▶sub remove {
Subroutine remove: not called CC=1 SCAR=6.9
Pod undocumented
117 0 my ($self) = @_;
118 my $formular_path = File::Spec->catdir( $self->project->project_path,
119 0 "formulars", $self->{directory} );
120  
121 0 File::Path::remove_tree($formular_path);
122 }
123  
124 1 1;
« JobControl/Dashboard.pm ↑ Summary JobControl/Mojolicious/Plugin/Audit.pm »