Bot-ChatBots
view release on metacpan or search on metacpan
lib/Bot/ChatBots/Role/WebHook.pm view on Meta::CPAN
package Bot::ChatBots::Role::WebHook;
use strict;
use warnings;
{ our $VERSION = '0.014'; }
use Ouch;
use Mojo::URL;
use Log::Any qw< $log >;
use Scalar::Util qw< blessed weaken refaddr >;
use Bot::ChatBots::Weak;
use Try::Tiny;
use Moo::Role;
with 'Bot::ChatBots::Role::Source';
requires 'process_updates';
has app => (
is => 'ro',
lazy => 1,
weak_ref => 1,
);
has code => (
is => 'ro',
lazy => 1,
builder => 'BUILD_code',
);
has method => (
is => 'ro',
lazy => 1,
builder => 'BUILD_method',
);
has path => (
is => 'ro',
lazy => 1,
builder => 'BUILD_path',
);
has _flags_tracker => (
is => 'ro',
lazy => 1,
builder => '_BUILD_flags_tracker',
);
has url => (is => 'ro');
sub BUILD_code { return 204 }
sub BUILD_method { return 'post' }
sub BUILD_path {
my $self = shift;
defined(my $url = $self->url)
or ouch 500, 'undefined path and url for WebHook';
return Mojo::URL->new($url)->path->to_string;
} ## end sub BUILD_path
sub _BUILD_flags_tracker {
my $self = shift;
$self->app->hook(after_dispatch => sub {
$self->_set_flags_rendered(@_);
});
return {};
}
sub _track_flags {
my ($self, $c, $flags) = @_;
$self->_flags_tracker->{refaddr($c)} = $flags;
( run in 0.757 second using v1.01-cache-2.11-cpan-39bf76dae61 )