Exobrain
view release on metacpan or search on metacpan
lib/Exobrain.pm view on Meta::CPAN
package Exobrain;
use v5.010;
use strict;
use warnings;
use feature ();
use autodie;
use Moose;
use Method::Signatures;
use Carp qw(croak);
use POSIX qw(tzset);
# ABSTRACT: Automate your life with Exobrain
our $VERSION = '1.08'; # VERSION: Generated by DZP::OurPkg:Version
# This forms the top-level Exobrain dispatch class. It's mostly
# lazy attributes, and nice sugar for doing common operations.
use Exobrain::Bus;
use Exobrain::Config;
use Exobrain::Message;
use Exobrain::Message::Raw;
has 'config' => (
is => 'ro',
isa => 'Exobrain::Config',
builder => '_build_config',
);
# Pub/Sub interfaces to our bus. These don't get generated unless
# our end code actually asks for them. Many things will only require
# one, or will use higher-level functions to do their work.
has 'pub' => (
is => 'ro',
isa => 'Exobrain::Bus',
builder => '_build_pub',
lazy => 1,
);
has 'sub' => (
is => 'ro',
isa => 'Exobrain::Bus',
builder => '_build_sub',
lazy => 1,
);
# import is called when we load the Exobrain class, and lets us
# automatically set strict, warnings, 5.10 features and Method::Signatures
# by default.
sub import {
strict->import();
warnings->import();
feature->import(':5.10');
# Method::Signatures needs a little more magic.
my $caller = caller;
## no critic (ProhibitStringyEval)
eval qq{
package $caller;
Method::Signatures->import;
1;
} or die $@;
## use critic
return;
}
# Right now we make sure anything using Exobrain is going to use
# the user's timezone (if set).
method BUILD(...) {
$self->_set_timezone();
return;
}
# This sets our timezone based upon what's in our config file,
# so any use of localtime() should use the user's local timezone.
method _set_timezone($tz?) {
$tz //= $self->config->{General}{timezone};
if ($tz) {
$ENV{TZ} = $tz; ## no critic RequireLocalizedPunctuationVars
tzset();
}
return;
}
sub _build_config { return Exobrain::Config->new; };
sub _build_pub { return Exobrain::Bus->new(type => 'PUB', exobrain => shift) }
sub _build_sub { return Exobrain::Bus->new(type => 'SUB', exobrain => shift) }
method watch_loop(
Str :$class!,
CodeRef :$filter,
CodeRef :$then!,
CodeRef :$debug?,
) {
# Load our component, because that means we immediately get
# an error if that class doesn't exist.
$self->_load_component($class);
while (my $event = $self->sub->get) {
my $namespace = $event->namespace;
( run in 2.235 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )