Mojolicious/Command/Author/inflate.pm

filter: Statementstmt 46.4% 13 / 28 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 47.3% 18 / 38 CC 6 SCAR 32.4
CC
6
Cov
41%
run
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 25.6
« Mojo/DOM/HTML.pm ↑ Summary Mojo/Template.pm »
1 package Mojolicious::Command::Author::inflate;
2 1 ▶use Mojo::Base 'Mojolicious::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use Mojo::Loader qw(data_section file_is_binary);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mojo::Util qw(encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 has description => 'Inflate embedded files to real files';
8 1 ▶has usage => sub { shift->extract_usage };
Subroutine __ANON__: called CC=1 SCAR=0.0
9  
10 0 ▶sub run {
Subroutine run: not called CC=6 SCAR=37.4
Pod documented
11 0 my $self = shift;
12  
13 # Find all embedded files
14 0 my %all;
15 0 my $app = $self->app;
16 0 for my $class (@{$app->renderer->classes}, @{$app->static->classes}) {
17 0 for my $name (keys %{data_section $class}) {
18 0 my $data = data_section $class, $name;
19 0 ▶ $data = encode 'UTF-8', $data unless file_is_binary $class, $name;
Branch: 1 branch
BranchTrueFalseTotal
unless file_is_binary($class, $name) 0 0 0
20 0 $all{$name} = $data;
21 }
22 }
23  
24 # Turn them into real files
25 0 for my $name (grep {/\.\w+$/} keys %all) {
26 0 ▶ my $prefix = $name =~ /\.\w+\.\w+$/ ? 'templates' : 'public';
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /\.\w+\.\w+$/u ? : 0 0 0
27 0 $self->write_file($self->rel_file("$prefix/$name"), $all{$name});
28 }
29 }
30  
31 1 1;
32  
33 =encoding utf8
34  
35 =head1 NAME
36  
37 Mojolicious::Command::Author::inflate - Inflate command
38  
39 =head1 SYNOPSIS
40  
41 Usage: APPLICATION inflate [OPTIONS]
42  
43 ./myapp.pl inflate
44  
45 Options:
46 -h, --help Show this summary of available options
47 --home <path> Path to home directory of your application, defaults to
48 the value of MOJO_HOME or auto-detection
49 -m, --mode <name> Operating mode for your application, defaults to the
50 value of MOJO_MODE/PLACK_ENV or "development"
51  
52 =head1 DESCRIPTION
53  
54 L<Mojolicious::Command::Author::inflate> turns templates and static files embedded in the C<DATA> sections of your
55 application into real files.
56  
57 This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
58 you're welcome to fork it.
59  
60 See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default.
61  
62 =head1 ATTRIBUTES
63  
64 L<Mojolicious::Command::Author::inflate> inherits all attributes from L<Mojolicious::Command> and implements the
65 following new ones.
66  
67 =head2 description
68  
69 my $description = $inflate->description;
70 $inflate = $inflate->description('Foo');
71  
72 Short description of this command, used for the command list.
73  
74 =head2 usage
75  
76 my $usage = $inflate->usage;
77 $inflate = $inflate->usage('Foo');
78  
79 Usage information for this command, used for the help screen.
80  
81 =head1 METHODS
82  
83 L<Mojolicious::Command::Author::inflate> inherits all methods from L<Mojolicious::Command> and implements the following
84 new ones.
85  
86 =head2 run
87  
88 $inflate->run(@ARGV);
89  
90 Run this command.
91  
92 =head1 SEE ALSO
93  
94 L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
95  
96 =cut
« Mojo/DOM/HTML.pm ↑ Summary Mojo/Template.pm »