File Coverage

blib/lib/Telebot/Command/bot/generate.pm
Criterion Covered Total %
statement 6 24 25.0
branch n/a
condition 0 2 0.0
subroutine 2 3 66.6
pod 1 1 100.0
total 9 30 30.0


line stmt bran cond sub pod time code
1             package Telebot::Command::bot::generate;
2 1     1   20051 use Mojo::Base 'Mojolicious::Command';
  1         2  
  1         6  
3              
4 1     1   189 use Mojo::Util qw(class_to_file class_to_path decamelize);
  1         1  
  1         398  
5              
6             has description => 'Generate Telebot application directory structure';
7             has usage => sub { shift->extract_usage };
8              
9             sub run {
10 0   0 0 1   my ($self, $class) = (shift, shift || 'MyBot');
11              
12             # Script
13 0           my $name = class_to_file $class;
14 0           $self->render_to_rel_file('mojo', "$name/script/$name", {class => $class});
15 0           $self->chmod_rel_file("$name/script/$name", 0744);
16              
17             # Application class
18 0           my $app = class_to_path $class;
19 0           $self->render_to_rel_file('appclass', "$name/lib/$app", {class => $class});
20              
21             # Config file (using the default moniker)
22 0           $self->render_to_rel_file('config', "$name/telebot.conf");
23              
24             # Controller
25 0           my $controller = "${class}::Controller::Site";
26 0           my $path = class_to_path $controller;
27 0           $self->render_to_rel_file('controller', "$name/lib/$path", {class => $controller});
28              
29             # Test
30 0           $self->render_to_rel_file('test', "$name/t/basic.t", {class => $class});
31              
32             # Static file
33 0           $self->render_to_rel_file('static', "$name/public/index.html");
34              
35             # Templates
36 0           $self->render_to_rel_file('layout', "$name/templates/layouts/default.html.ep");
37 0           $self->render_to_rel_file('site_index', "$name/templates/site/index.html.ep");
38            
39             # Handlers
40 0           for my $type (qw(
41             Update
42             CallbackQuery
43             ChannelPost
44             ChatJoinRequest
45             ChatMember
46             ChosenInlineResult
47             EditedChannelPost
48             EditedMessage
49             InlineQuery
50             Message
51             MyChatMember
52             Poll
53             PollAnswer
54             PreCheckoutQuery
55             ShippingQuery
56             )) {
57 0           my $handler = "${class}::Handler::${type}";
58 0           my $path = class_to_path $handler;
59 0           $self->render_to_rel_file('handler', "$name/lib/$path", {class => $handler});
60             }
61             }
62              
63             1;
64              
65             =encoding utf8
66              
67             =head1 NAME
68              
69             Telebot::Command::bot::generate - Bot generator command
70              
71             =head1 SYNOPSIS
72              
73             Usage: APPLICATION bot generate [OPTIONS] [NAME]
74              
75             telebot bot generate
76             telebot bot generate TestBot
77             telebot bot generate My::TestBot
78              
79             Options:
80             -h, --help Show this summary of available options
81              
82             =head1 DESCRIPTION
83              
84             L generates application directory structures for fully functional
85             L applications.
86              
87             This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
88             you're welcome to fork it.
89              
90             =head1 ATTRIBUTES
91              
92             L inherits all attributes from L and implements the
93             following new ones.
94              
95             =head2 description
96              
97             my $description = $app->description;
98             $app = $app->description('Foo');
99              
100             Short description of this command, used for the command list.
101              
102             =head2 usage
103              
104             my $usage = $app->usage;
105             $app = $app->usage('Foo');
106              
107             Usage information for this command, used for the help screen.
108              
109             =head1 METHODS
110              
111             L inherits all methods from L and implements the
112             following new ones.
113              
114             =head2 run
115              
116             $app->run(@ARGV);
117              
118             Run this command.
119              
120             =head1 SEE ALSO
121              
122             L, L, L.
123              
124             =cut
125              
126             __DATA__