File Coverage

blib/lib/Mojolicious/Command/Author/generate/plugin.pm
Criterion Covered Total %
statement 15 15 100.0
branch 4 4 100.0
condition 2 2 100.0
subroutine 3 3 100.0
pod 1 1 100.0
total 25 25 100.0


line stmt bran cond sub pod time code
1             package Mojolicious::Command::Author::generate::plugin;
2 1     1   7 use Mojo::Base 'Mojolicious::Command';
  1         14  
  1         7  
3              
4 1     1   8 use Mojo::Util qw(camelize class_to_path getopt);
  1         4  
  1         390  
5              
6             has description => 'Generate Mojolicious plugin directory structure';
7             has usage => sub { shift->extract_usage };
8              
9             sub run {
10 3     3 1 53 my ($self, @args) = @_;
11              
12 3 100       14 die $self->usage unless getopt \@args, 'f|full' => \(my $full);
13              
14             # Class
15 2   100     11 my $name = $args[0] // 'MyPlugin';
16 2 100       10 my $class = $full ? $name : "Mojolicious::Plugin::$name";
17 2         11 my $dir = join '-', split(/::/, $class);
18 2         8 my $app = class_to_path $class;
19 2         26 $self->render_to_rel_file('class', "$dir/lib/$app", {class => $class, name => $name});
20              
21             # Test
22 2         19 $self->render_to_rel_file('test', "$dir/t/basic.t", {name => $name});
23              
24             # Makefile
25 2         23 $self->render_to_rel_file('makefile', "$dir/Makefile.PL", {class => $class, path => $app});
26             }
27              
28             1;
29              
30             =encoding utf8
31              
32             =head1 NAME
33              
34             Mojolicious::Command::Author::generate::plugin - Plugin generator command
35              
36             =head1 SYNOPSIS
37              
38             Usage: APPLICATION generate plugin [OPTIONS] [NAME]
39              
40             mojo generate plugin
41             mojo generate plugin TestPlugin
42             mojo generate plugin -f MyApp::Plugin::AwesomeFeature
43              
44             Options:
45             -f, --full Do not prepend "Mojolicious::Plugin::" to the plugin name
46             -h, --help Show this summary of available options
47              
48             =head1 DESCRIPTION
49              
50             L generates directory structures for fully functional L
51             plugins.
52              
53             This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
54             you're welcome to fork it.
55              
56             See L for a list of commands that are available by default.
57              
58             =head1 ATTRIBUTES
59              
60             L inherits all attributes from L and implements
61             the following new ones.
62              
63             =head2 description
64              
65             my $description = $plugin->description;
66             $plugin = $plugin->description('Foo');
67              
68             Short description of this command, used for the command list.
69              
70             =head2 usage
71              
72             my $usage = $plugin->usage;
73             $plugin = $plugin->usage('Foo');
74              
75             Usage information for this command, used for the help screen.
76              
77             =head1 METHODS
78              
79             L inherits all methods from L and implements the
80             following new ones.
81              
82             =head2 run
83              
84             $plugin->run(@ARGV);
85              
86             Run this command.
87              
88             =head1 SEE ALSO
89              
90             L, L, L.
91              
92             =cut
93              
94             __DATA__