blib/lib/Mojolicious/Plugin/Fondation/Asset.pm

filter: Statementstmt 91.6% 33 / 36 Branchbran 83.3% 5 / 6 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 4 / 4 Podpod 33.3% 1 / 3 totaltotal 79.3% 46 / 58 CC 9 SCAR 18.1
CC
9
Cov
85%
fondation_finalyze
8.4
register
2.0
BEGIN
1.0
CRAP 6.1
« lib/Mojolicious/Plugin/Fondation/Asset/Command/asset.pm ↑ Summary
1 package Mojolicious::Plugin::Fondation::Asset;
2 3 $Mojolicious::Plugin::Fondation::Asset::VERSION = '0.04';
3 # ABSTRACT: AssetPack wrapper -- generate via command, load pre-built def at runtime
4  
5 3 ▶use Mojo::Base 'Mojolicious::Plugin', -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8  
9 11 ▶sub fondation_meta {
Subroutine fondation_meta: called CC=1 SCAR=0.0
Pod undocumented
10 return {
11 11 dependencies => [],
12 after => ['Fondation::OpenAPI'],
13 defaults => {
14 fondation_init => [
15 ['asset', 'generate', '-y'],
16 ],
17 fondation_upgrade => [
18 ['asset', 'generate', '-y'],
19 ],
20 fondation_clean => ['share/assets/'],
21 },
22 setup => {
23 label => 'AssetPack',
24 description => 'Asset configuration',
25 parameters => [
26 {
27 key => 'asset_dir',
28 label => 'Asset output directory',
29 type => 'string',
30 default => 'share/assets',
31 required => 1,
32 placeholder => 'share/assets',
33 },
34 {
35 key => 'pipes',
36 label => 'Pipes',
37 type => 'string',
38 default => 'Fetch,Sass,Css,Combine',
39 required => 1,
40 placeholder => 'Fetch,Sass,Css,Combine',
41 },
42 ],
43 },
44 };
45 }
46  
47 11 ▶sub register ($self, $app, $conf = {}) {
Subroutine register: called CC=2 SCAR=6.9
Pod documented
48 11 $app->defaults('asset.config' => $conf);
49  
50 11 push @{$app->commands->namespaces},
51 'Mojolicious::Plugin::Fondation::Asset::Command';
52  
53 11 return $self;
54 }
55  
56 11 ▶sub fondation_finalyze ($self, $app, $long_name) {
Subroutine fondation_finalyze: called CC=8 SCAR=21.3
Pod undocumented
57 11 ▶ my $conf = $app->defaults('asset.config') // {};
Condition50%1/2
$app->defaults("asset.config") // {}
l!l
110
MC/DC0%0/1
$app->defaults("asset.config") // {}
$app->defaults("asset.config")
Truth table50%1/2
A
A= $app->defaults("asset.config")
Aresult
11
00
58 11 ▶ my $asset_dir = $conf->{asset_dir} // 'share/assets';
Condition50%1/2
$conf->{"asset_dir"} // "share/assets"
l!l
011
MC/DC0%0/1
$conf->{"asset_dir"} // "share/assets"
$conf->{"asset_dir"}
Truth table50%1/2
A
A= $conf->{"asset_dir"}
Aresult
11
00
59 11 my $def_file = $app->home->child($asset_dir, 'assetpack.def');
60  
61 11 ▶ unless (-f $def_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $def_file) 8 3 11
62 8 $self->log->warn(
63 "No assetpack.def found at $def_file. "
64 . "Run 'asset generate' first."
65 );
66 8 return;
67 }
68  
69 # Load AssetPack with custom store path so it finds the def and writes bundles there
70 3 ▶ my @pipes = split /\s*,\s*/, ($conf->{pipes} // 'Fetch,Sass,Css,Combine');
Condition50%1/2
$conf->{"pipes"} // "Fetch,Sass,Css,Combine"
l!l
03
MC/DC0%0/1
$conf->{"pipes"} // "Fetch,Sass,Css,Combine"
$conf->{"pipes"}
Truth table50%1/2
A
A= $conf->{"pipes"}
Aresult
11
00
71 3 $app->plugin('AssetPack' => {
72 pipes => \@pipes,
73 });
74  
75 # Override the default store path (normally 'assets') with the configured directory
76 3 my $asset = $app->asset;
77 3 $asset->store->paths([$app->home->child($asset_dir)]);
78  
79 # Register local public/ and plugin public dirs for asset resolution
80 3 push @{ $asset->store->paths }, $app->home->child('public');
81  
82 3 for my $long (@{ $app->manager->load_order }) {
83 9 my $entry = $app->manager->registry->{$long};
84 9 my $public_dir = $entry->{public_dir};
85 9 ▶ if ($public_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($public_dir) 6 3 9
86 6 push @{ $asset->store->paths }, $public_dir->to_string;
87 }
88 }
89  
90 # Process assets to register topics (skips already-cached external files).
91 # Skip during 'fondation refresh' — the clean phase will remove assets/,
92 # then 'asset generate -y' in the init phase will rebuild from scratch.
93 0 ▶ if (grep { $_ eq 'refresh' } @ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "refresh";} @ARGV) 0 3 3
94 0 $self->log->debug("Skipping AssetPack process during fondation refresh");
95 0 return;
96 }
97  
98 3 $asset->process();
99  
100 3 $self->log->debug("AssetPack loaded from $def_file");
101 }
102  
103 3 1;
104  
105 __END__
« lib/Mojolicious/Plugin/Fondation/Asset/Command/asset.pm ↑ Summary