Activity.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Base/Common.pm ↑ Summary
1 package Daje::Workflow::GenerateSQL::Activity;
2 1 ▶use Mojo::Base 'Daje::Workflow::Common::Activity::Base', -base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 # NAME
5 # ====
6 ##
7 # Daje::Workflow::GenerateSQL::Activity - It's a to generate SQL from a json description
8 #
9 # SYNOPSIS
10 # ========
11 ##
12 # use Daje::Workflow::GenerateSQL::Activity;
13 #
14 # my $object = $activity->{activity}->new(
15 # context => $context,
16 # db => $db,
17 # error => $error,
18 # model => $model,
19 # activity_data => $activity_data,
20 # );
21 #
22 # $object->process();
23 #
24 # DESCRIPTION
25 # ===========
26 ##
27 # Daje::Workflow::GenerateSQL::Activity is ...
28 #
29 # LICENSE
30 # =======
31 #
32 # Copyright (C) janeskil1525.
33 #
34 # This library is free software; you can redistribute it and/or modify
35 # it under the same terms as Perl itself.
36 #
37 # AUTHOR
38 # ======
39 #
40 # janeskil1525 E<lt>janeskil1525@gmail.comE<gt>
41 #
42  
43 our $VERSION = "1.07";
44  
45 1 ▶use Mojo::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use Daje::Workflow::GenerateSQL::Manager::Sql;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 0 ▶use Daje::Tools::Datasections;
Subroutine BEGIN: called CC=1 SCAR=2.6
48 use Daje::Config;
49 use Daje::Workflow::Templates;
50  
51 sub process ($self) {
52  
53 my @data;
54 my $files_list = $self->context->{context}->{changed_files};
55 my $length = scalar @{$files_list};
56 for (my $i = 0; $i < $length; $i++) {
57 if ($self->error->has_error() == 0) {
58 if (my $sql = $self->_process_sql(@{$files_list}[$i])) {
59 my $data->{data} = $sql;
60 $data->{file} = Mojo::File->new(@{$files_list}[$i])->basename;
61 $data->{file} =~ s/.json//g;
62 push(@data, $data);
63 $self->model->insert_history(@{$files_list}[$i], "Daje::Workflow::GenerateSQL::Activity;");
64 }
65 }
66 }
67 $self->context->{context}->{sql} = \@data;
68  
69 return;
70 }
71  
72 sub _process_sql($self, $file) {
73 my $sql = "";
74 eval {
75 my $table = $self->_load_table($file);
76 $table->generate_table();
77 $sql = $table->sql();
78 };
79 $self->error->add_error($@) if defined $@;
80  
81  
82  
83 # try {
84 # Daje::Generate::Output::Sql::SqlManager->new(
85 # config => $self->config,
86 # file => $file,
87 # sql => $sql,
88 # )->save_file();
89 # } catch ($e) {
90 # die "Could not create output '$e'";
91 # };
92  
93 return $sql;
94 }
95  
96 sub _load_table($self, $file) {
97  
98 my $json = Daje::Config->new()->load_json($file);
99 my $templates = Daje::Workflow::Templates->new(
100 data_sections => $self->activity_data->{template}->{data_sections},
101 source => $self->activity_data->{template}->{source},
102 error => $self->error,
103 )->load_templates();
104  
105 my $table;
106  
107 eval {
108 $table = Daje::Workflow::GenerateSQL::Manager::Sql->new(
109 templates => $templates,
110 json => $json,
111 error => $self->error,
112 );
113 };
114 $self->error->add_error($@) if defined $@ and length($@) > 0;
115  
116 return $table;
117 }
118  
119 1;
120 __END__
« Base/Common.pm ↑ Summary