BusyBird

 view release on metacpan or  search on metacpan

lib/BusyBird/Main.pm  view on Meta::CPAN

package BusyBird::Main;
use v5.8.0;
use strict;
use warnings;
use BusyBird::Timeline;
use BusyBird::Watcher::Aggregator;
use BusyBird::Log qw(bblog);
use BusyBird::Config;
use Tie::IxHash;
use Carp;
use Try::Tiny;

our @CARP_NOT = qw(BusyBird::Timeline BusyBird::Config);

sub new {
    my ($class) = @_;
    tie(my %timelines, 'Tie::IxHash');
    my $self = bless {
        timelines => \%timelines,
        config => BusyBird::Config->new(type => "global", with_default => 1),
    }, $class;
    return $self;
}

sub timeline {
    my ($self, $name) = @_;
    my $timeline = $self->get_timeline($name);
    if(not defined $timeline) {
        $timeline = $self->create_timeline($name);
        $self->install_timeline($timeline);
    }
    return $timeline;
}

sub create_timeline {
    my ($self, $name) = @_;
    return BusyBird::Timeline->new(name => $name, storage => $self->get_config("default_status_storage"));
}

sub get_timeline {
    my ($self, $name) = @_;
    return $self->{timelines}{$name};
}

sub get_all_timelines {
    my ($self) = @_;
    return values %{$self->{timelines}};
}

sub install_timeline {
    my ($self, $timeline) = @_;
    if($timeline->name eq "") {
        bblog("warn", "Invalid timeline name (it's empty)");
        return;
    }
    if($timeline->name =~ qr{/}) {
        bblog("warn", "Invalid timeline name (it contains /)");
        return;
    }
    $self->{timelines}{$timeline->name} = $timeline;
}

sub uninstall_timeline {
    my ($self, $name) = @_;
    my $timeline = $self->get_timeline($name);
    delete $self->{timelines}{$name};
    return $timeline;
}

sub set_config {
    shift()->{config}->set_config(@_);



( run in 0.680 second using v1.01-cache-2.11-cpan-39bf76dae61 )