lib/Daje/Workflow/Activities/Delete.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 49 CC 5 SCAR 28.7
CC
5
Cov
0%
delete
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 17.6
1 package Daje::Workflow::Activities::Delete;
2 use Mojo::Base 'Daje::Workflow::Common::Activity::Base', -base, -signatures;
3 use v5.42;
4  
5 # NAME
6 # ====
7 #
8 # Daje::Workflow::Activities::Delete - It deletes database objects
9 #
10 # SYNOPSIS
11 # ========
12 #
13 # use Daje::Workflow::Activities::Delete
14 #
15 # use Mojo::Loader qw(load_class);
16 #
17 # Expected input from workflow
18 #
19 # "activity_data": {
20 # "class": "Model to use"
21 # }
22 #
23 # DESCRIPTION
24 # ===========
25 #
26 # Daje::Workflow::Activities::Delete just deletes a record in a table
27 #
28 # LICENSE
29 # =======
30 #
31 # Copyright (C) janeskil1525.
32 #
33 # This library is free software; you can redistribute it and/or modify
34 # it under the same terms as Perl itself.
35 #
36 # AUTHOR
37 # ======
38 #
39 # janeskil1525 E<lt>janeskil1525@gmail.comE<gt>
40 #
41  
42 use Data::Dumper;
43 use Mojo::Loader qw(load_class);
44  
45 sub delete ($self) {
46  
47 $self->model->insert_history(
48 "Delete data",
49 "Daje::Workflow::Activities::Delete::delete",
50 1
51 );
52  
53 my $data = $self->context->{context}->{payload};
54 my $class = $self->activity_data->{class};
55 if (my $e = load_class $class) {
56 $self->error->add_error($e);
57 $self->error->add_error($class . " Not found ");
58 }
59 return 0 if $self->error->has_error();
60 say "Class = " . $class;
61  
62 try {
63 my $dbclass = $class->new(db => $self->db);
64 if (exists $data->{$dbclass->primary_key_name} and $data->{$dbclass->primary_key_name} > 0) {
65 $self->model->insert_history(
66 "Delete object " . $dbclass->table_name() . Dumper($data), " $class->delete", 2
67 );
68  
69 my $result = $dbclass->delete($data->{$dbclass->primary_key_name});
70 if($result->{result} == 0) {
71 $self->error->add_error($result->{error});
72 }
73 };
74 } catch ($e) {
75 $self->error->add_error($e);
76 };
77  
78 return 1;
79 }
80 1;
81 #################### pod generated by Pod::Autopod - keep this line to make pod updates possible ####################
82  
83 =head1 NAME
84  
85  
86 Daje::Workflow::Activities::Delete - It deletes database objects
87  
88  
89  
90 =head1 SYNOPSIS
91  
92  
93 use Daje::Workflow::Activities::Delete
94  
95 use Mojo::Loader qw(load_class);
96  
97 Expected input from workflow
98  
99 "activity_data": {
100 "class": "Model to use"
101 }
102  
103  
104  
105 =head1 DESCRIPTION
106  
107  
108 Daje::Workflow::Activities::Delete just deletes a record in a table
109  
110  
111  
112 =head1 REQUIRES
113  
114 L<Mojo::Loader>
115  
116 L<Data::Dumper>
117  
118 L<v5.42>
119  
120 L<Mojo::Base>
121  
122  
123 =head1 METHODS
124  
125 =head2 delete
126  
127 delete();
128  
129  
130 =head1 AUTHOR
131  
132  
133 janeskil1525 E<lt>janeskil1525@gmail.comE<gt>
134  
135  
136  
137 =head1 LICENSE
138  
139  
140 Copyright (C) janeskil1525.
141  
142 This library is free software; you can redistribute it and/or modify
143 it under the same terms as Perl itself.
144  
145  
146  
147 =cut
148