« lib/Mojolicious/Plugin/Fondation/Workflow.pm
↑ Summary
lib/Mojolicious/Plugin/Fondation/Workflow/Proxy.pm »
| 1 | package Mojolicious::Plugin::Fondation::Workflow::Action::Workflow; | ||||||||||||||||||||||||||||
| 2 | 2 | $Mojolicious::Plugin::Fondation::Workflow::Action::Workflow::VERSION = '0.02'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Post-load action — copies plugin workflow YAMLs to share/workflows/ | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Mojo::Base 'Mojolicious::Plugin::Fondation::Action::Base', -signatures; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Workflow::Factory; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 9 | # after_load — called by Fondation Manager for each plugin | ||||||||||||||||||||||||||||
| 10 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | sub after_load ($self, $long, $conf, $share_dir) { | ||||||||||||||||||||||||||
|
Subroutine
after_load: called CC=10 SCAR=41.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | return unless $share_dir && -d $share_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$share_dir and -d $share_dir
MC/DC50%1/2
$share_dir and -d $share_dir
$share_dir
-d $share_dir
Truth table66%2/3
A and B
A= $share_dirB= -d $share_dir
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 4 | my $workflows_dir = $share_dir->child('workflows'); | |||||||||||||||||||||||||||
| 16 | 4 | ▶ | return unless -d $workflows_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | my $app = $self->manager->app; | |||||||||||||||||||||||||||
| 19 | 0 | my $out_dir = $app->home->child('share', 'workflows'); | |||||||||||||||||||||||||||
| 20 | 0 | ▶ | $out_dir->make_path unless -d $out_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | my $factory = Workflow::Factory->instance; | |||||||||||||||||||||||||||
| 23 | 0 | my $copied = 0; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | for my $file ($workflows_dir->list({dir => 0})->each) { | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | next unless $file->basename =~ /^(.+)\.ya?ml$/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | my $type = $1; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | my $dest = $out_dir->child($file->basename); | |||||||||||||||||||||||||||
| 30 | 0 | my $existed = -f $dest; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # Copy to app's share/workflows/ | ||||||||||||||||||||||||||||
| 33 | 0 | $file->copy_to($dest->to_string); | |||||||||||||||||||||||||||
| 34 | 0 | $copied++; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # Register with factory only on first run (before register() picks it up) | ||||||||||||||||||||||||||||
| 37 | # On subsequent runs, register() already loaded it from share/workflows/ | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | next if $existed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | require YAML; | |||||||||||||||||||||||||||
| 41 | 0 | my $yaml = eval { YAML::LoadFile($dest->to_string) }; | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | $self->log->warn("Failed to load workflow YAML $dest: $@"); | |||||||||||||||||||||||||||
| 44 | 0 | next; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | $factory->add_config( | ||||||||||||||||||||||||||||
| 48 | 0 | workflow => [$yaml], | |||||||||||||||||||||||||||
| 49 | action => [$yaml], | ||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | $self->log->debug("Registered workflow '$type' from $dest"); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return unless $copied; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | $self->log->info("$long: $copied workflow(s) copied to share/workflows/"); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||