BusyBird
view release on metacpan or search on metacpan
lib/BusyBird/Flow.pm view on Meta::CPAN
package BusyBird::Flow;
use v5.8.0;
use strict;
use warnings;
use Async::Queue;
use BusyBird::Log qw(bblog);
use CPS qw(kforeach);
use Carp;
use Scalar::Util qw(weaken);
use Try::Tiny;
sub new {
my ($class) = @_;
my $self = bless {
filters => [],
}, $class;
$self->{queue} = $self->_create_queue();
return $self;
}
sub _create_queue {
my ($self) = @_;
weaken $self;
return Async::Queue->new(concurrency => 1, worker => sub {
my ($data, $done) = @_;
kforeach $self->{filters}, sub {
my ($filter, $knext) = @_;
try {
$filter->($data, sub {
my ($result) = @_;
if(ref($result) && ref($result) eq 'ARRAY') {
$data = $result;
}else {
lib/BusyBird/Main/PSGI/View.pm view on Meta::CPAN
package BusyBird::Main::PSGI::View;
use v5.8.0;
use strict;
use warnings;
use BusyBird::Util qw(set_param split_with_entities);
use Carp;
use Try::Tiny;
use Scalar::Util qw(weaken);
use JSON qw(to_json);
use Text::Xslate qw(html_builder html_escape);
use File::Spec;
use Encode ();
use JavaScript::Value::Escape ();
use DateTime::TimeZone;
use BusyBird::DateTime::Format;
use BusyBird::Log qw(bblog);
use BusyBird::SafeData qw(safed);
use Cache::Memory::Simple;
lib/BusyBird/Main/PSGI/View.pm view on Meta::CPAN
return undef if !defined($url_builder) || !defined($text_builder);
my $url_str = $url_builder->($segment->{text}, $segment->{entity}, $status);
return undef if !_is_valid_link_url($url_str);
my $text_str = $text_builder->($segment->{text}, $segment->{entity}, $status);
$text_str = "" if not defined $text_str;
return _html_link_status_text($text_str, $url_str);
}
sub template_functions_for_timeline {
my ($self, $timeline_name) = @_;
weaken $self; ## in case the functions are kept by $self
return {
bb_timestamp => sub {
my ($timestamp_string) = @_;
return "" if !$timestamp_string;
my $timezone = $self->_get_timezone($self->{main_obj}->get_timeline_config($timeline_name, "time_zone"));
my $dt = BusyBird::DateTime::Format->parse_datetime($timestamp_string);
return "" if !defined($dt);
$dt->set_time_zone($timezone);
$dt->set_locale($self->{main_obj}->get_timeline_config($timeline_name, "time_locale"));
return $dt->strftime($self->{main_obj}->get_timeline_config($timeline_name, "time_format"));
lib/BusyBird/Timeline.pm view on Meta::CPAN
use BusyBird::Util qw(set_param);
use BusyBird::Log qw(bblog);
use BusyBird::Flow;
use BusyBird::Watcher::Aggregator;
use BusyBird::DateTime::Format 0.04;
use BusyBird::Config;
use Async::Selector 1.0;
use Data::UUID;
use Carp;
use Storable qw(dclone);
use Scalar::Util qw(weaken looks_like_number);
use DateTime;
our @CARP_NOT = qw(BusyBird::Config);
sub new {
my ($class, %args) = @_;
my $self = bless {
filter_flow => BusyBird::Flow->new,
selector => Async::Selector->new,
unacked_counts => {total => 0},
lib/BusyBird/Timeline.pm view on Meta::CPAN
$self->_log('error', "error while updating unacked count: $error");
return;
}
$self->{unacked_counts} = $unacked_counts;
$self->{selector}->trigger('unacked_counts');
});
}
sub _init_selector {
my ($self) = @_;
weaken $self;
$self->{selector}->register(unacked_counts => sub {
my ($exp_unacked_counts) = @_;
if(!defined($exp_unacked_counts) || ref($exp_unacked_counts) ne 'HASH') {
croak "unacked_counts watcher: condition input must be a hash-ref";
}
return { %{$self->{unacked_counts}} } if !%$exp_unacked_counts;
foreach my $key (keys %$exp_unacked_counts) {
my $exp_val = $exp_unacked_counts->{$key} || 0;
my $got_val = $self->{unacked_counts}{$key} || 0;
return { %{$self->{unacked_counts}} } if $exp_val != $got_val;
lib/BusyBird/Util.pm view on Meta::CPAN
package BusyBird::Util;
use v5.8.0;
use strict;
use warnings;
use Scalar::Util qw(blessed weaken);
use Carp;
use Exporter 5.57 qw(import);
use BusyBird::DateTime::Format;
use BusyBird::Log qw(bblog);
use BusyBird::SafeData qw(safed);
use DateTime;
use Future::Q 0.040;
use File::HomeDir;
use File::Spec;
lib/BusyBird/Util.pm view on Meta::CPAN
croak "tracking_timeline must be a BusyBird::Timeline.";
}
if(!blessed($main_timeline) || !$main_timeline->isa("BusyBird::Timeline")) {
croak "main_timeline must be a BusyBird::Timeline.";
}
my $name_tracking = $tracking_timeline->name;
my $name_main = $main_timeline->name;
if($name_tracking eq $name_main) {
croak "tracking_timeline and main_timeline must be different timelines.";
}
weaken(my $track = $tracking_timeline);
$tracking_timeline->add_filter_async(sub {
my ($statuses, $done) = @_;
if(!defined($track)) {
$done->($statuses);
return;
}
$track->contains(query => $statuses, callback => sub {
my ($error, $contained, $not_contained) = @_;
if(defined($error)) {
bblog("error", "tracking timeline '$name_tracking' contains() error: $error");
( run in 0.335 second using v1.01-cache-2.11-cpan-65fba6d93b7 )