Zapp/Type.pm

filter: Statementstmt 40.7% 11 / 27 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 30.0% 3 / 10 Podpod 100% 7 / 7 totaltotal 45.6% 21 / 46 CC 4 SCAR 15.5
CC
4
Cov
38%
config_field
12.0
input_field
6.0
process_config
2.0
CRAP 4.7
« Zapp/Task/Action.pm ↑ Summary Zapp/Type/SelectBox.pm »
1 package Zapp::Type;
2 # ABSTRACT: Input/output handling for data types
3  
4 #pod =head1 SYNOPSIS
5 #pod
6 #pod package My::Type;
7 #pod use Mojo::Base 'Zapp::Type';
8 #pod sub process_config( $self, $c, $form_value ) {
9 #pod # Return the $config_value
10 #pod }
11 #pod
12 #pod sub process_input( $self, $c, $config_value, $form_value ) {
13 #pod # Return the $input_value
14 #pod }
15 #pod
16 #pod sub task_input( $self, $config_value, $input_value ) {
17 #pod # Return the $task_value
18 #pod }
19 #pod
20 #pod sub task_output( $self, $config_value, $task_value ) {
21 #pod # Return the $input_value
22 #pod }
23 #pod
24 #pod __DATA__
25 #pod @@ config.html.ep
26 #pod %# Form to configure the input
27 #pod
28 #pod @@ input.html.ep
29 #pod %# Form for the user to fill in
30 #pod
31 #pod @@ output.html.ep
32 #pod %# Template to display the value
33 #pod
34 #pod =head1 DESCRIPTION
35 #pod
36 #pod This is the base class for Zapp types. Types are configured when
37 #pod building a plan, then filled out by the user when running the plan.
38 #pod Tasks then get the type's value as input, and can return a value
39 #pod of the given type.
40 #pod
41 #pod =head2 Type Value
42 #pod
43 #pod The type value returned from L</process_input> should contain all the
44 #pod information needed to use the value in a task. This does not need to be
45 #pod the actual content that tasks will use, but can be an identifier to look
46 #pod up that content.
47 #pod
48 #pod For example, the L<Zapp::Type::File> type stores a path relative to the
49 #pod application's home directory. When saving plans or starting runs, the
50 #pod file gets uploaded, saved to the home directory, and the path saved to
51 #pod the database. When a task needs the file, it gets the full path as
52 #pod a string.
53 #pod
54 #pod Another example could be a map of user passwords in a config file. The
55 #pod type value could be the username, which would be stored in the database
56 #pod for the plan/run. Then when a task needed the password, it could be
57 #pod looked up using the username.
58 #pod
59 #pod =head1 SEE ALSO
60 #pod
61 #pod =cut
62  
63 10 ▶use Mojo::Base -base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 10 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
65 10 ▶use Mojo::Loader qw( data_section );
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 #pod =head1 ATTRIBUTES
68 #pod
69 #pod =head2 app
70 #pod
71 #pod The application object. A L<Zapp> object.
72 #pod
73 #pod =cut
74  
75 10 has app =>;
76  
77 #pod =head1 METHODS
78 #pod
79 #pod =head2 config_field
80 #pod
81 #pod Get the field for configuration input. Reads the C<@@ config.html.ep>
82 #pod file from the C<__DATA__> section of the type class.
83 #pod
84 #pod =cut
85  
86 0 ▶sub config_field( $self, $c, $config_value=undef ) {
Subroutine config_field: not called CC=3 SCAR=24.8
Pod documented
87 0 my $class = blessed $self;
88 0 my $tmpl = data_section( $class, 'config.html.ep' );
89 0 ▶ return '' if !$tmpl;
Branch: 1 branch
BranchTrueFalseTotal
unless $tmpl 0 0 0
90 # XXX: Use Mojo::Template directly to get better names than 'inline
91 # template XXXXXXXXXXXX'?
92 0 return $c->render_to_string(
93 inline => $tmpl,
94 self => $self,
95 config => $config_value,
96 );
97 }
98  
99 #pod =head2 process_config
100 #pod
101 #pod Process the form value for configuring this type. Return the type config
102 #pod to be stored in the database.
103 #pod
104 #pod =cut
105  
106 ▶sub process_config( $self, $c, $form_value ) {
Subroutine process_config: not called CC=1 SCAR=6.9
Pod documented
107 0 ...;
108 }
109  
110 #pod =head2 input_field
111 #pod
112 #pod Get the field for user input. Reads the C<@@ input.html.ep> file from
113 #pod the C<__DATA__> section of the type class.
114 #pod
115 #pod =cut
116  
117 0 ▶sub input_field( $self, $c, $config_value, $input_value=undef ) {
Subroutine input_field: not called CC=2 SCAR=17.9
Pod documented
118 0 my $class = blessed $self;
119 0 my $tmpl = data_section( $class, 'input.html.ep' );
120 # XXX: Use Mojo::Template directly to get better names than 'inline
121 # template XXXXXXXXXXXX'?
122 0 return $c->render_to_string(
123 inline => $tmpl,
124 self => $self,
125 config => $config_value,
126 value => $input_value,
127 );
128 }
129  
130 #pod =head2 process_input
131 #pod
132 #pod Process the form value when saving a run. Return the type value to be
133 #pod stored in the database.
134 #pod
135 #pod =cut
136  
137 ▶sub process_input( $self, $c, $config_value, $form_value ) {
Subroutine process_input: not called CC=1 SCAR=6.9
Pod documented
138 0 ...;
139 }
140  
141 #pod =head2 task_input
142 #pod
143 #pod Convert the type value stored in the database to the value used by the
144 #pod task.
145 #pod
146 #pod =cut
147  
148 ▶sub task_input( $self, $config_value, $input_value ) {
Subroutine task_input: not called CC=1 SCAR=6.9
Pod documented
149 0 ...;
150 }
151  
152 #pod =head2 task_output
153 #pod
154 #pod Convert a value from a task's output into a type value to be stored in
155 #pod the database.
156 #pod
157 #pod =cut
158  
159 ▶sub task_output( $self, $config_value, $task_value ) {
Subroutine task_output: not called CC=1 SCAR=6.9
Pod documented
160 0 ...;
161 }
162  
163 #pod =head2 display_value
164 #pod
165 #pod Show the value on the run page.
166 #pod
167 #pod =cut
168  
169 ▶sub display_value( $self, $c, $config_value, $input_value ) {
Subroutine display_value: not called CC=1 SCAR=6.9
Pod documented
170 0 my $class = blessed $self;
171 0 my $tmpl = data_section( $class, 'output.html.ep' );
172 # XXX: Use Mojo::Template directly to get better names than 'inline
173 # template XXXXXXXXXXXX'?
174 0 return $c->render_to_string(
175 inline => $tmpl,
176 self => $self,
177 config => $config_value,
178 value => $input_value,
179 );
180 }
181  
182 10 1;
183  
184 __END__
« Zapp/Task/Action.pm ↑ Summary Zapp/Type/SelectBox.pm »