1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
# Copyright (C) 2008-2010, Sebastian Riedel.
package Mojolicious::Command::Inflate;
use strict;
use warnings;
use base 'Mojo::Command';
use Getopt::Long 'GetOptions';
use Mojo::Loader;
__PACKAGE__->attr(description => <<'EOF');
Inflate embedded files to real files.
EOF
__PACKAGE__->attr(usage => <<"EOF");
usage: $0 inflate [OPTIONS]
--class <class> Class to inflate.
--prefix <path> Path prefix for generated files, defaults to templates.
EOF
# Eternity with nerds. It's the Pasadena Star Trek convention all over again.
sub run {
my $self = shift;
# Class
my $class = 'main';
my $prefix = 'templates';
# Options
@ARGV = @_ if @_;
GetOptions(
'class=s' => sub { $class = $_[1] },
'prefix=s' => sub { $prefix = $_[1] }
);
# Load class
my $e = Mojo::Loader->load($class);
die $e if ref $e;
# Generate
my $all = $self->get_all_data($class);
for my $file (keys %$all) {
my $path = $self->rel_file("$prefix/$file");
$self->write_file($path, $all->{$file});
}
return $self;
}
1;
__END__
=head1 NAME
Mojolicious::Command::Inflate - Inflate Command
=head1 SYNOPSIS
use Mojolicious::Command::Inflate;
my $inflate = Mojolicious::Command::Inflate->new;
$inflate->run(@ARGV);
=head1 DESCRIPTION
L<Mojolicious::Command::Inflate> prints all your application routes.
=head1 ATTRIBUTES
L<Mojolicious::Command::Inflate> inherits all attributes from
L<Mojo::Command> and implements the following new ones.
=head2 C<description>
my $description = $inflate->description;
$inflate = $inflate->description('Foo!');
Short description of this command, used for the command list.
=head2 C<usage>
my $usage = $inflate->usage;
$inflate = $inflate->usage('Foo!');
Usage information for this command, used for the help screen.
=head1 METHODS
L<Mojolicious::Command::Inflate> inherits all methods from L<Mojo::Command>
and implements the following new ones.
=head2 C<run>
$inflate = $inflate->run(@ARGV);
Run this command.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicious.org>.
=cut
|