App/Dochazka/REST/Mason.pm

filter: Statementstmt 68.5% 24 / 35 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 70.0% 7 / 10 Podpod 100% 1 / 1 totaltotal 47.0% 32 / 68 CC 7 SCAR 32.3
CC
7
Cov
47%
__ANON__
56.0
init_singleton
2.0
__ANON__
2.0
CRAP 25.2
« App/Dochazka/REST/Model/Employee.pm ↑ Summary App/Dochazka/REST/Model/Component.pm »
1 # *************************************************************************
2 # Copyright (c) 2014-2015, SUSE LLC
3 #
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 #
16 # 3. Neither the name of SUSE LLC nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
31 # *************************************************************************
32  
33 # ------------------------
34 # store and dispense Mason interpreter singleton
35 # ------------------------
36  
37 package App::Dochazka::REST::Mason;
38  
39 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 42 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 42 ▶use App::CELL qw( $CELL $log $site );
Subroutine BEGIN: called CC=1 SCAR=0.0
43 42 ▶use Mason;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 42 ▶use Params::Validate qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
45 42 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47  
48  
49 =head1 NAME
50  
51 App::Dochazka::REST::Mason - Mason interpreter singleton
52  
53  
54  
55 =head1 SYNOPSIS
56  
57 use App::Dochazka::REST::Mason qw( $interp );
58  
59  
60  
61 =head1 DESCRIPTION
62  
63 Mason interpreter singleton.
64  
65 =cut
66  
67  
68  
69 =head1 EXPORTS
70  
71 =cut
72  
73 42 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
74 42 our @EXPORT_OK = qw( $comp_root $interp );
75  
76  
77  
78 =head1 PACKAGE VARIABLES
79  
80 This module stores and initializes the L<Mason> interpreter singleton object.
81  
82 =cut
83  
84 42 our ( $comp_root, $interp );
85  
86  
87  
88 =head1 FUNCTIONS
89  
90  
91 =head2 init_singleton
92  
93 Initialize the C<$interp> singleton. Takes a C<comp_root> and a
94 C<data_dir> which are expected to exist and be owned by the effective user.
95  
96 Idempotent.
97  
98 FIXME: Add parameters to the Mason->new() call as needed.
99  
100 =cut
101  
102 0 ▶sub init_singleton {
Subroutine init_singleton: not called CC=1 SCAR=6.9
Pod documented
103 0 my @ARGS = @_;
104 0 my %ARGS;
105 0 my $status = $CELL->status_ok;
106 0 ▶ try {
Subroutine __ANON__: not called CC=7 SCAR=40.3
107 0 %ARGS = validate(
108 @ARGS, {
109 comp_root => { type => SCALAR },
110 data_dir => { type => SCALAR },
111 }
112 );
113 die "Mason comp_root $ARGS{comp_root} has a problem" unless
114 (
115 -r $ARGS{comp_root} and
116 -w $ARGS{comp_root} and
117 -x $ARGS{comp_root}
118 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
unless -r $ARGS{"comp_root"} and -w $ARGS{"comp_root"} and -x $ARGS{"comp_root"} 0 0 0
Condition0%0/6
-r $ARGS{"comp_root"} and -w $ARGS{"comp_root"} and -x $ARGS{"comp_root"}
!ll&&!rl&&r
000
-r $ARGS{"comp_root"} and -w $ARGS{"comp_root"}
!ll&&!rl&&r
000
MC/DC0%0/3
-r $ARGS{"comp_root"} and -w $ARGS{"comp_root"} and -x $ARGS{"comp_root"}
-r $ARGS{"comp_root"} -w $ARGS{"comp_root"} -x $ARGS{"comp_root"}
Truth table0%0/4
A and B and C
A= -r $ARGS{"comp_root"}B= -w $ARGS{"comp_root"}C= -x $ARGS{"comp_root"}
ABCresult
0XX0
10X0
1100
1111
119 die "Mason comp_root $ARGS{data_dir} has a problem" unless
120 (
121 -r $ARGS{comp_root} and
122 -w $ARGS{comp_root} and
123 -x $ARGS{comp_root}
124 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
unless -r $ARGS{"comp_root"} and -w $ARGS{"comp_root"} and -x $ARGS{"comp_root"} 0 0 0
Condition0%0/6
-r $ARGS{"comp_root"} and -w $ARGS{"comp_root"} and -x $ARGS{"comp_root"}
!ll&&!rl&&r
000
-r $ARGS{"comp_root"} and -w $ARGS{"comp_root"}
!ll&&!rl&&r
000
MC/DC0%0/3
-r $ARGS{"comp_root"} and -w $ARGS{"comp_root"} and -x $ARGS{"comp_root"}
-r $ARGS{"comp_root"} -w $ARGS{"comp_root"} -x $ARGS{"comp_root"}
Truth table0%0/4
A and B and C
A= -r $ARGS{"comp_root"}B= -w $ARGS{"comp_root"}C= -x $ARGS{"comp_root"}
ABCresult
0XX0
10X0
1100
1111
125 $interp = Mason->new(
126 comp_root => $ARGS{comp_root},
127 data_dir => $ARGS{data_dir},
128 0 class_header => q(
129 use App::CELL qw( $CELL $log $meta $site );
130 ),
131 );
132 0 $comp_root = $ARGS{comp_root};
133 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
134 0 $status = $CELL->status_crit( 'DOCHAZKA_MASON_INIT_FAIL', args => [ $_ ] );
135 0 };
136 0 return $status;
137 }
138  
139 42 1;
« App/Dochazka/REST/Model/Employee.pm ↑ Summary App/Dochazka/REST/Model/Component.pm »