lib/Mojolicious/Plugin/Fondation/Workflow/Action/Workflow.pm

filter: Statementstmt 32.3% 11 / 34 Branchbran 21.4% 3 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 3 / 3 Podpod 0.0% 0 / 1 totaltotal 35.0% 20 / 57 CC 10 SCAR 39.8
CC
10
Cov
31%
after_load
63.9
BEGIN
1.0
BEGIN
1.0
CRAP 53.4
« 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
BranchTrueFalseTotal
unless $share_dir and -d $share_dir 2 4 6
Condition66%2/3
$share_dir and -d $share_dir
!ll&&!rl&&r
024
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
ABresult
0X0
100
111
14  
15 4 my $workflows_dir = $share_dir->child('workflows');
16 4 ▶ return unless -d $workflows_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $workflows_dir 4 0 4
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
BranchTrueFalseTotal
unless -d $out_dir 0 0 0
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
BranchTrueFalseTotal
unless $file->basename =~ /^(.+)\.ya?ml$/iu 0 0 0
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
BranchTrueFalseTotal
if $existed 0 0 0
39  
40 0 require YAML;
41 0 my $yaml = eval { YAML::LoadFile($dest->to_string) };
42 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
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
BranchTrueFalseTotal
unless $copied 0 0 0
56 0 $self->log->info("$long: $copied workflow(s) copied to share/workflows/");
57 }
58  
59 2 1;
60  
61 __END__
« lib/Mojolicious/Plugin/Fondation/Workflow.pm ↑ Summary lib/Mojolicious/Plugin/Fondation/Workflow/Proxy.pm »