1 | package Mojolicious::Command::inflate;
|
---|
2 | use Mojo::Base 'Mojolicious::Command';
|
---|
3 |
|
---|
4 | use Mojo::Loader qw(data_section file_is_binary);
|
---|
5 | use Mojo::Util 'encode';
|
---|
6 |
|
---|
7 | has description => 'Inflate embedded files to real files';
|
---|
8 | has usage => sub { shift->extract_usage };
|
---|
9 |
|
---|
10 | sub run {
|
---|
11 | my $self = shift;
|
---|
12 |
|
---|
13 | # Find all embedded files
|
---|
14 | my %all;
|
---|
15 | my $app = $self->app;
|
---|
16 | for my $class (@{$app->renderer->classes}, @{$app->static->classes}) {
|
---|
17 | for my $name (keys %{data_section $class}) {
|
---|
18 | my $data = data_section $class, $name;
|
---|
19 | $data = encode 'UTF-8', $data unless file_is_binary $class, $name;
|
---|
20 | $all{$name} = $data;
|
---|
21 | }
|
---|
22 | }
|
---|
23 |
|
---|
24 | # Turn them into real files
|
---|
25 | for my $name (grep {/\.\w+$/} keys %all) {
|
---|
26 | my $prefix = $name =~ /\.\w+\.\w+$/ ? 'templates' : 'public';
|
---|
27 | $self->write_file($self->rel_file("$prefix/$name"), $all{$name});
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | 1;
|
---|
32 |
|
---|
33 | =encoding utf8
|
---|
34 |
|
---|
35 | =head1 NAME
|
---|
36 |
|
---|
37 | Mojolicious::Command::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::inflate> turns templates and static files embedded in
|
---|
55 | the C<DATA> sections of your application into real files.
|
---|
56 |
|
---|
57 | This is a core command, that means it is always enabled and its code a good
|
---|
58 | example for learning to build new commands, you're welcome to fork it.
|
---|
59 |
|
---|
60 | See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are
|
---|
61 | available by default.
|
---|
62 |
|
---|
63 | =head1 ATTRIBUTES
|
---|
64 |
|
---|
65 | L<Mojolicious::Command::inflate> inherits all attributes from
|
---|
66 | L<Mojolicious::Command> and implements the following new ones.
|
---|
67 |
|
---|
68 | =head2 description
|
---|
69 |
|
---|
70 | my $description = $inflate->description;
|
---|
71 | $inflate = $inflate->description('Foo');
|
---|
72 |
|
---|
73 | Short description of this command, used for the command list.
|
---|
74 |
|
---|
75 | =head2 usage
|
---|
76 |
|
---|
77 | my $usage = $inflate->usage;
|
---|
78 | $inflate = $inflate->usage('Foo');
|
---|
79 |
|
---|
80 | Usage information for this command, used for the help screen.
|
---|
81 |
|
---|
82 | =head1 METHODS
|
---|
83 |
|
---|
84 | L<Mojolicious::Command::inflate> inherits all methods from
|
---|
85 | L<Mojolicious::Command> and implements the following new ones.
|
---|
86 |
|
---|
87 | =head2 run
|
---|
88 |
|
---|
89 | $inflate->run(@ARGV);
|
---|
90 |
|
---|
91 | Run this command.
|
---|
92 |
|
---|
93 | =head1 SEE ALSO
|
---|
94 |
|
---|
95 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
|
---|
96 |
|
---|
97 | =cut
|
---|