| 1 | package Telebot::Command::bot::generate; | ||||||||||||
| 2 | 1 | ▶ | use Mojo::Base 'Mojolicious::Command'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | |||||||||||||
| 4 | 1 | ▶ | use Mojo::Util qw(class_to_file class_to_path decamelize); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 1 | has description => 'Generate Telebot application directory structure'; | |||||||||||
| 7 | 1 | ▶ | has usage => sub { shift->extract_usage }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 0 | ▶ | sub run { | ||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 10 | 0 | ▶ | my ($self, $class) = (shift, shift || 'MyBot'); | ||||||||||
|
Condition0%0/2
shift() || 'MyBot'
MC/DC0%0/1
shift() || 'MyBot'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 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 | 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<Telebot::Command::bot::generate> generates application directory structures for fully functional | ||||||||||||
| 85 | L<Telebot> 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<Telebot::Command::bot::generate> inherits all attributes from L<Mojolicious::Command> 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<Telebot::Command::generate> inherits all methods from L<Mojolicious::Command> 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<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||||||||||||
| 123 | |||||||||||||
| 124 | =cut | ||||||||||||
| 125 | |||||||||||||
| 126 | __DATA__ | ||||||||||||