| 1 | package Daje::Workflow::Activities::Tools::Generate::Perl; | ||
| 2 | use Mojo::Base 'Daje::Workflow::Activities::Tools::Generate::Base', -base, -signatures; | ||
| 3 | use v5.42; | ||
| 4 | |||
| 5 | use POSIX; | ||
| 6 | use Mojo::Util qw { camelize }; | ||
| 7 | use String::Util 'trim'; | ||
| 8 | |||
| 9 | sub generate_perl($self) { | ||
| 10 | $self->model->insert_history( | ||
| 11 | "Generate Perl", | ||
| 12 | "Daje::Workflow::Activities::Tools::Generate::Perl::generate_perl", | ||
| 13 | 1 | ||
| 14 | ); | ||
| 15 | |||
| 16 | my $tools_projects_pkey = $self->context->{context}->{payload}->{tools_projects_fkey}; | ||
| 17 | my @outputs = split /,/, $self->get_parameter('Perl', 'Outputs', $tools_projects_pkey);; | ||
| 18 | try { | ||
| 19 | my $documents; | ||
| 20 | my $source = $self->get_parameter('Perl', 'Template Source', $tools_projects_pkey); | ||
| 21 | foreach my $output (@outputs) { | ||
| 22 | my $generate = "generate_" . trim($output); | ||
| 23 | my $doc = $self->$generate($tools_projects_pkey, $source); | ||
| 24 | if (ref $doc eq 'ARRAY') { | ||
| 25 | my $length = scalar @{ $doc }; | ||
| 26 | for (my $i = 0; $i < $length; $i++) { | ||
| 27 | push @{$documents}, @{ $doc }[$i]; | ||
| 28 | } | ||
| 29 | } else { | ||
| 30 | push @{$documents}, $doc; | ||
| 31 | } | ||
| 32 | |||
| 33 | } | ||
| 34 | my @data; | ||
| 35 | my $length = scalar @{$documents}; | ||
| 36 | for (my $i = 0; $i < $length; $i++) { | ||
| 37 | my $data->{data} = @{$documents}[$i]->{document}; | ||
| 38 | $data->{file} = @{ $documents }[$i]->{file}; | ||
| 39 | $data->{new_only} = @{ $documents }[$i]->{new_only} | ||
| 40 | if exists @{ $documents }[$i]->{new_only}; | ||
| 41 | $data->{path} = 1; | ||
| 42 | push(@data, $data); | ||
| 43 | } | ||
| 44 | $self->context->{context}->{payload}->{perl} = \@data; | ||
| 45 | |||
| 46 | } catch($e) { | ||
| 47 | say $e | ||
| 48 | $self->error->add_error($e); | ||
| 49 | }; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub generate_controller($self, $tools_projects_pkey, $source) { | ||
| 53 | my $docs; | ||
| 54 | my $project_name = $self->load_project_name($tools_projects_pkey); | ||
| 55 | if($self->load_active_tables($tools_projects_pkey)) { | ||
| 56 | my $length = scalar @{$self->tables}; | ||
| 57 | for (my $i = 0; $i < $length; $i++) { | ||
| 58 | my $table->{table} = @{$self->tables}[$i]; | ||
| 59 | $table->{project_name} = $project_name; | ||
| 60 | $table->{class_name} = camelize $table->{project_name} . "_" . $table->{table}->{table_name}; | ||
| 61 | $table->{date_time} = strftime "%Y-%m-%d %H:%M:%S", localtime time; | ||
| 62 | $self->versions($table); | ||
| 63 | my $documents = $self->build_documents($source,'controller'); | ||
| 64 | @{ $documents }[0]->{class_name} = $table->{class_name}; | ||
| 65 | @{ $documents }[0]->{file} = $self->get_parameter('Perl', 'Controller file path', $tools_projects_pkey) . $table->{class_name} . '.pm'; | ||
| 66 | @{ $documents }[0]->{new_only} = 1; | ||
| 67 | push @{$docs}, @{ $documents }[0]; | ||
| 68 | $documents = $self->build_documents($source,'tests_controller'); | ||
| 69 | @{ $documents }[0]->{class_name} = $table->{class_name}; | ||
| 70 | @{ $documents }[0]->{file} = $self->get_parameter('Perl', 'Test file path', $tools_projects_pkey) . $table->{table}->{table_name} . '.controller.t'; | ||
| 71 | @{ $documents }[0]->{new_only} = 0; | ||
| 72 | push @{$docs}, @{ $documents }[0]; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | return $docs; | ||
| 77 | } | ||
| 78 | |||
| 79 | sub generate_super_controller($self, $tools_projects_pkey, $source) { | ||
| 80 | my $docs; | ||
| 81 | my $project_name = $self->load_project_name($tools_projects_pkey); | ||
| 82 | if($self->load_active_tables($tools_projects_pkey)) { | ||
| 83 | my $length = scalar @{$self->tables}; | ||
| 84 | for (my $i = 0; $i < $length; $i++) { | ||
| 85 | my $table->{table} = @{$self->tables}[$i]; | ||
| 86 | $table->{project_name} = $project_name; | ||
| 87 | $table->{fields} = $self->load_active_table_fields($table->{table}->{tools_objects_pkey}); | ||
| 88 | $table->{class_name} = camelize $table->{project_name} . "_" . $table->{table}->{table_name}; | ||
| 89 | $table->{date_time} = strftime "%Y-%m-%d %H:%M:%S", localtime time; | ||
| 90 | $self->versions($table); | ||
| 91 | my $documents = $self->build_documents($source,'super_controller'); | ||
| 92 | @{ $documents }[0]->{class_name} = $table->{class_name}; | ||
| 93 | @{ $documents }[0]->{file} = $self->get_parameter('Perl', 'Controller file path', $tools_projects_pkey) . 'Super/' . $table->{class_name} . '.pm'; | ||
| 94 | @{ $documents }[0]->{new_only} = 0; | ||
| 95 | push @{$docs}, @{ $documents }[0]; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | return $docs; | ||
| 100 | } | ||
| 101 | |||
| 102 | sub generate_helpers($self, $tools_projects_pkey, $source) { | ||
| 103 | my $docs; | ||
| 104 | my $tables; | ||
| 105 | my $project_name = $self->load_project_name($tools_projects_pkey); | ||
| 106 | my $class_name = camelize $project_name; | ||
| 107 | if($self->load_active_tables($tools_projects_pkey)) { | ||
| 108 | $tables->{project_name} = $project_name; | ||
| 109 | $tables->{class_name} = $class_name; | ||
| 110 | $tables->{date_time} = strftime "%Y-%m-%d %H:%M:%S", localtime time; | ||
| 111 | my $length = scalar @{$self->tables}; | ||
| 112 | for (my $i = 0; $i < $length; $i++) { | ||
| 113 | my $table = @{$self->tables}[$i]; | ||
| 114 | $table->{class_name} = camelize $project_name . "_" . $table->{table_name}; | ||
| 115 | $table->{fields} = $self->load_active_table_fields($table->{tools_objects_pkey}); | ||
| 116 | push @{$tables->{tables}}, $table; | ||
| 117 | } | ||
| 118 | $self->versions($tables); | ||
| 119 | my $documents = $self->build_documents($source,'helpers'); | ||
| 120 | @{ $documents }[0]->{file} = $self->get_parameter('Perl', 'Helpers file path', $tools_projects_pkey) . "Helpers.pm"; | ||
| 121 | @{ $documents }[0]->{new_only} = 0; | ||
| 122 | push @{$docs}, @{ $documents }[0]; | ||
| 123 | } | ||
| 124 | return $docs; | ||
| 125 | } | ||
| 126 | |||
| 127 | sub generate_routes($self, $tools_projects_pkey, $source) { | ||
| 128 | my $docs; | ||
| 129 | my $tables; | ||
| 130 | my $project_name = $self->load_project_name($tools_projects_pkey); | ||
| 131 | my $class_name = camelize $project_name; | ||
| 132 | if($self->load_active_tables($tools_projects_pkey)) { | ||
| 133 | $tables->{project_name} = $project_name; | ||
| 134 | $tables->{class_name} = $class_name; | ||
| 135 | $tables->{date_time} = strftime "%Y-%m-%d %H:%M:%S", localtime time; | ||
| 136 | my $length = scalar @{$self->tables}; | ||
| 137 | for (my $i = 0; $i < $length; $i++) { | ||
| 138 | my $table = @{$self->tables}[$i]; | ||
| 139 | $table->{class_name} = camelize $project_name . "_" . $table->{table_name}; | ||
| 140 | $table->{fields} = $self->load_active_table_fields($table->{tools_objects_pkey}); | ||
| 141 | push @{$tables->{tables}}, $table; | ||
| 142 | } | ||
| 143 | $self->versions($tables); | ||
| 144 | my $documents = $self->build_documents($source,'routes'); | ||
| 145 | @{ $documents }[0]->{file} = $self->get_parameter('Perl', 'Routes file path', $tools_projects_pkey) . "Routes.pm"; | ||
| 146 | @{ $documents }[0]->{new_only} = 0; | ||
| 147 | push @{$docs}, @{ $documents }[0]; | ||
| 148 | } | ||
| 149 | return $docs; | ||
| 150 | } | ||
| 151 | |||
| 152 | sub generate_db_model($self, $tools_projects_pkey, $source) { | ||
| 153 | my $docs; | ||
| 154 | my $project_name = $self->load_project_name($tools_projects_pkey); | ||
| 155 | if($self->load_active_tables($tools_projects_pkey)) { | ||
| 156 | my $length = scalar @{$self->tables}; | ||
| 157 | for (my $i = 0; $i < $length; $i++) { | ||
| 158 | my $table->{table} = @{$self->tables}[$i]; | ||
| 159 | $table->{class_name} = camelize $project_name . "_" . $table->{table}->{table_name}; | ||
| 160 | $table->{date_time} = strftime "%Y-%m-%d %H:%M:%S", localtime time; | ||
| 161 | $self->versions($table); | ||
| 162 | my $documents = $self->build_documents($source,'db_model'); | ||
| 163 | @{ $documents }[0]->{class_name} = $table->{class_name}; | ||
| 164 | @{ $documents }[0]->{file} = $self->get_parameter('Perl', 'Model file path', $tools_projects_pkey) . $table->{class_name} . '.pm'; | ||
| 165 | @{ $documents }[0]->{new_only} = 0; | ||
| 166 | push @{$docs}, @{ $documents }[0]; | ||
| 167 | $documents = $self->build_documents($source,'tests_database_model'); | ||
| 168 | @{ $documents }[0]->{class_name} = $table->{class_name}; | ||
| 169 | @{ $documents }[0]->{file} = $self->get_parameter('Perl', 'Test file path', $tools_projects_pkey) . $table->{table}->{table_name} . '.model.t'; | ||
| 170 | @{ $documents }[0]->{new_only} = 0; | ||
| 171 | push @{$docs}, @{ $documents }[0]; | ||
| 172 | } | ||
| 173 | } | ||
| 174 | return $docs; | ||
| 175 | } | ||
| 176 | |||
| 177 | sub generate_db_model_super($self, $tools_projects_pkey, $source) { | ||
| 178 | my $docs; | ||
| 179 | my $project_name = $self->load_project_name($tools_projects_pkey); | ||
| 180 | if($self->load_active_tables($tools_projects_pkey)) { | ||
| 181 | my $length = scalar @{$self->tables}; | ||
| 182 | for (my $i = 0; $i < $length; $i++) { | ||
| 183 | my $table->{table} = @{$self->tables}[$i]; | ||
| 184 | $table->{project_name} = $project_name; | ||
| 185 | $table->{fields} = $self->load_active_table_fields($table->{table}->{tools_objects_pkey}); | ||
| 186 | $table->{class_name} = camelize $table->{project_name} . "_" . $table->{table}->{table_name}; | ||
| 187 | $table->{date_time} = strftime "%Y-%m-%d %H:%M:%S", localtime time; | ||
| 188 | $self->versions($table); | ||
| 189 | my $documents = $self->build_documents($source,'db_model_super'); | ||
| 190 | @{ $documents }[0]->{class_name} = $table->{class_name}; | ||
| 191 | @{ $documents }[0]->{file} = $self->get_parameter('Perl', 'Model file path', $tools_projects_pkey) . 'Super/' . $table->{class_name} . '.pm'; | ||
| 192 | @{ $documents }[0]->{new_only} = 0; | ||
| 193 | push @{$docs}, @{ $documents }[0]; | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | return $docs; | ||
| 198 | } | ||
| 199 | |||
| 200 | sub generate_plugin($self, $tools_projects_pkey, $source) { | ||
| 201 | |||
| 202 | my $versions->{project_name} = $self->load_project_name($tools_projects_pkey); | ||
| 203 | |||
| 204 | $versions->{plugin_name} = camelize $versions->{project_name}; | ||
| 205 | $versions->{date_time} = strftime "%Y-%m-%d %H:%M:%S", localtime time; | ||
| 206 | $self->versions($versions); | ||
| 207 | my $documents = $self->build_documents($source,'plugin'); | ||
| 208 | @{ $documents }[0]->{file} = $self->get_parameter('Perl', 'Plugin file path', $tools_projects_pkey) . $versions->{plugin_name} . '.pm'; | ||
| 209 | @{ $documents }[0]->{new_only} = 1; | ||
| 210 | |||
| 211 | return @{$documents}[0]; | ||
| 212 | } | ||
| 213 | 1; |