1

First touch to satisfy perlcritic

This commit is contained in:
eleksir
2020-10-28 18:18:09 +03:00
parent f816840e14
commit 033441c513
30 changed files with 74 additions and 65 deletions

View File

@@ -1,11 +1,10 @@
package Teapot::Bot;
$Teapot::Bot::VERSION = '0.021';
use strict;
use warnings;
$Teapot::Bot::VERSION = '0.021';
# ABSTRACT: A base class to make your very own Telegram bot
1;
__END__

View File

@@ -1,7 +1,6 @@
package Teapot::Bot::Brain;
$Teapot::Bot::Brain::VERSION = '0.021';
# ABSTRACT: A base class to make your very own Telegram bot
# ABSTRACT: A base class to make your very own Telegram bot
use Mojo::Base -base;
@@ -16,6 +15,8 @@ use Data::Dumper;
use Teapot::Bot::Object::Message;
$Teapot::Bot::Brain::VERSION = '0.021';
# base class for building telegram robots with Mojolicious
has longpoll_time => 60;
has ua => sub { Mojo::UserAgent->new->inactivity_timeout(shift->longpoll_time + 15) };
@@ -50,6 +51,7 @@ sub add_repeating_task {
# kick it off
$repeater->();
return;
}
@@ -58,6 +60,7 @@ sub add_listener {
my $coderef = shift;
push @{ $self->listeners }, $coderef;
return;
}
sub init {
@@ -71,6 +74,7 @@ sub think {
$self->_add_getUpdates_handler;
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
return;
}
@@ -106,7 +110,6 @@ sub sendMessage {
# check reply_markup is the right kind
if (exists $args->{reply_markup}) {
my $reply_markup = $args->{reply_markup};
die "bad reply_markup supplied"
if ( ref($reply_markup) ne 'Teapot::Bot::Object::InlineKeyboardMarkup' &&
ref($reply_markup) ne 'Teapot::Bot::Object::ReplyKeyboardMarkup' &&
ref($reply_markup) ne 'Teapot::Bot::Object::ReplyKeyboardRemove' &&
@@ -201,6 +204,8 @@ sub _add_getUpdates_handler {
$http_active = 0;
});
});
return;
}
# process a message which arrived via getUpdates
@@ -227,6 +232,8 @@ sub _process_message {
# call the listener code, supplying ourself and the update
$listener->($self, $update);
}
return;
}

View File

@@ -1,12 +1,12 @@
package Teapot::Bot::Object::Animation;
$Teapot::Bot::Object::Animation::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'Animation' type.
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::PhotoSize;
use Carp qw/croak/;
$Teapot::Bot::Object::Animation::VERSION = '0.021';
has 'file_id';
has 'width';
has 'height';

View File

@@ -1,10 +1,10 @@
package Teapot::Bot::Object::Audio;
$Teapot::Bot::Object::Audio::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Audio' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::Audio::VERSION = '0.021';
has 'file_id';
has 'duration';
has 'performer';

View File

@@ -1,10 +1,10 @@
package Teapot::Bot::Object::Base;
$Teapot::Bot::Object::Base::VERSION = '0.021';
# ABSTRACT: The base class for all Teapot::Bot::Object objects.
use Mojo::Base -base;
$Teapot::Bot::Object::Base::VERSION = '0.021';
has '_brain'; # a reference to our brain

View File

@@ -1,12 +1,12 @@
package Teapot::Bot::Object::Chat;
$Teapot::Bot::Object::Chat::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Chat' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::ChatPhoto;
use Teapot::Bot::Object::Message;
$Teapot::Bot::Object::Chat::VERSION = '0.021';
has 'id';
has 'type';
has 'title';
@@ -34,12 +34,12 @@ sub fields {
sub is_user {
shift->id > 0;
return shift->id > 0;
}
sub is_group {
shift->id < 0;
return shift->id < 0;
}
1;

View File

@@ -1,10 +1,10 @@
package Teapot::Bot::Object::ChatPhoto;
$Teapot::Bot::Object::ChatPhoto::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'ChatPhoto' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::ChatPhoto::VERSION = '0.021';
has 'small_file_id';
has 'big_file_id';

View File

@@ -1,10 +1,10 @@
package Teapot::Bot::Object::Contact;
$Teapot::Bot::Object::Contact::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Contact' objects.
use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::Contact::VERSION = '0.021';
has 'phone_number';
has 'first_name';
has 'last_name';

View File

@@ -1,12 +1,12 @@
package Teapot::Bot::Object::Document;
$Teapot::Bot::Object::Document::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Document' objects
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::PhotoSize;
$Teapot::Bot::Object::Document::VERSION = '0.021';
has 'file_id';
has 'thumb'; #PhotoSize
has 'file_name';

View File

@@ -1,10 +1,10 @@
package Teapot::Bot::Object::EncryptedCredentials;
$Teapot::Bot::Object::EncryptedCredentials::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'EncryptedCredentials' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::EncryptedCredentials::VERSION = '0.021';
has 'data';
has 'hash';
has 'secret';

View File

@@ -1,10 +1,10 @@
package Teapot::Bot::Object::EncryptedPassportElement;
$Teapot::Bot::Object::EncryptedPassportElement::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'EncryptedPassportElement' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::EncryptedPassportElement::VERSION = '0.021';
# XXX Implement rest of this
# https://core.telegram.org/bots/api#encryptedpassportelement

View File

@@ -1,5 +1,4 @@
package Teapot::Bot::Object::Game;
$Teapot::Bot::Object::Game::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'Game' type.
@@ -8,6 +7,8 @@ use Teapot::Bot::Object::PhotoSize;
use Teapot::Bot::Object::Animation;
use Teapot::Bot::Object::MessageEntity;
$Teapot::Bot::Object::Game::VERSION = '0.021';
has 'title';
has 'description';
has 'photo'; # Array of PhotoSize
@@ -23,7 +24,7 @@ sub fields {
};
}
sub arrays { qw/photo text_entities/ }
sub arrays { return qw/photo text_entities/; }
1;

View File

@@ -1,12 +1,12 @@
package Teapot::Bot::Object::InlineKeyboardButton;
$Teapot::Bot::Object::InlineKeyboardButton::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'InlineKeyboardButton' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::LoginUrl;
use Teapot::Bot::Object::CallbackGame;
$Teapot::Bot::Object::InlineKeyboardButton::VERSION = '0.021';
has 'text';
has 'url';
has 'login_url'; #LoginUrl

View File

@@ -1,11 +1,11 @@
package Teapot::Bot::Object::InlineKeyboardMarkup;
$Teapot::Bot::Object::InlineKeyboardMarkup::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'InlineKeyboardMarkup' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::InlineKeyboardButton;
$Teapot::Bot::Object::InlineKeyboardMarkup::VERSION = '0.021';
has 'inline_keyboard';
sub fields {

View File

@@ -1,10 +1,10 @@
package Teapot::Bot::Object::Invoice;
$Teapot::Bot::Object::Invoice::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Invoice' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::Invoice::VERSION = '0.021';
has 'title';
has 'description';
has 'start_parameter';

View File

@@ -1,10 +1,10 @@
package Teapot::Bot::Object::Location;
$Teapot::Bot::Object::Location::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'Location' type.
use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::Location::VERSION = '0.021';
has 'longitude';
has 'latitude';

View File

@@ -1,10 +1,10 @@
package Teapot::Bot::Object::LoginUrl;
$Teapot::Bot::Object::LoginUrl::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'LoginUrl' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::LoginUrl::VERSION = '0.021';
has 'url';
has 'forward_text';
has 'bot_username';

View File

@@ -1,8 +1,6 @@
package Teapot::Bot::Object::Message;
$Teapot::Bot::Object::Message::VERSION = '0.021';
# ABSTRACT: The base class for the Telegram type "Message".
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::User;
@@ -30,6 +28,8 @@ use Teapot::Bot::Object::InlineKeyboardMarkup;
use Data::Dumper;
$Teapot::Bot::Object::Message::VERSION = '0.021';
# basic message stuff
has 'message_id';
has 'from'; # User
@@ -124,7 +124,7 @@ sub fields {
}
sub arrays {
qw/photo entities caption_entities new_chat_members new_chat_photo/
return qw/photo entities caption_entities new_chat_members new_chat_photo/;
}

View File

@@ -1,11 +1,11 @@
package Teapot::Bot::Object::MessageEntity;
$Teapot::Bot::Object::MessageEntity::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'MessageEntity' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::User;
$Teapot::Bot::Object::MessageEntity::VERSION = '0.021';
has 'type';
has 'offset';
has 'length';

View File

@@ -1,12 +1,12 @@
package Teapot::Bot::Object::PassportData;
$Teapot::Bot::Object::PassportData::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'PassportData' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::EncryptedPassportElement;
use Teapot::Bot::Object::EncryptedCredentials;
$Teapot::Bot::Object::PassportData::VERSION = '0.021';
has 'data'; # Array of EncryptedPassportElement
has 'credentials'; # EncryptedCredentials
@@ -15,8 +15,9 @@ sub fields {
'Teapot::Bot::Object::EncryptedCredentials' => [qw/credentials/],
};
}
sub arrays {
qw/data/;
return qw/data/;
}
1;

View File

@@ -1,11 +1,11 @@
package Teapot::Bot::Object::PhotoSize;
$Teapot::Bot::Object::PhotoSize::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'PhotoSize' type.
use Mojo::Base 'Teapot::Bot::Object::Base';
use Carp qw/croak/;
$Teapot::Bot::Object::PhotoSize::VERSION = '0.021';
has 'file_id';
has 'width';
has 'height';

View File

@@ -1,11 +1,10 @@
package Teapot::Bot::Object::Poll;
$Teapot::Bot::Object::Poll::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Poll' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::PollOption;
$Teapot::Bot::Object::Poll::VERSION = '0.021';
has 'id';
has 'question';
@@ -20,7 +19,7 @@ sub fields {
}
sub arrays {
qw/options/;
return qw/options/;
}
1;

View File

@@ -1,10 +1,10 @@
package Teapot::Bot::Object::PollOption;
$Teapot::Bot::Object::PollOption::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'PollOption' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::PollOption::VERSION = '0.021';
has 'text';
has 'voter_count';

View File

@@ -1,11 +1,11 @@
package Teapot::Bot::Object::Sticker;
$Teapot::Bot::Object::Sticker::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'Sticker' type.
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::PhotoSize;
$Teapot::Bot::Object::Sticker::VERSION = '0.021';
has 'file_id';
has 'width';
has 'height';

View File

@@ -1,11 +1,11 @@
package Teapot::Bot::Object::SuccessfulPayment;
$Teapot::Bot::Object::SuccessfulPayment::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'SuccessfulPayment' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
# use Teapot::Bot::Object::OrderInfo;
$Teapot::Bot::Object::SuccessfulPayment::VERSION = '0.021';
has 'currency';
has 'total_amount';
has 'invoice_payload';

View File

@@ -1,10 +1,11 @@
package Teapot::Bot::Object::User;
$Teapot::Bot::Object::User::VERSION = '0.021';
# ABSTRACT: The base class for Telegram message 'User' type.
use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::User::VERSION = '0.021';
has 'id';
has 'is_bot';
has 'first_name';

View File

@@ -1,11 +1,11 @@
package Teapot::Bot::Object::Venue;
$Teapot::Bot::Object::Venue::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'LoginUrl' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::Location;
$Teapot::Bot::Object::Venue::VERSION = '0.021';
has 'location'; #Location
has 'title';
has 'address';

View File

@@ -1,11 +1,11 @@
package Teapot::Bot::Object::Video;
$Teapot::Bot::Object::Video::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Video' object.
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::PhotoSize;
$Teapot::Bot::Object::Video::VERSION = '0.021';
has 'file_id';
has 'width';
has 'height';

View File

@@ -1,11 +1,12 @@
package Teapot::Bot::Object::VideoNote;
$Teapot::Bot::Object::VideoNote::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'VideoNote' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
use Teapot::Bot::Object::PhotoSize;
$Teapot::Bot::Object::VideoNote::VERSION = '0.021';
has 'file_id';
has 'length';
has 'duration';

View File

@@ -1,10 +1,10 @@
package Teapot::Bot::Object::Voice;
$Teapot::Bot::Object::Voice::VERSION = '0.021';
# ABSTRACT: The base class for Telegram 'Voice' type objects
use Mojo::Base 'Teapot::Bot::Object::Base';
$Teapot::Bot::Object::Voice::VERSION = '0.021';
has 'file_id';
has 'duration';
has 'mime_type';