AnyEvent-Campfire-Stream
view release on metacpan or search on metacpan
lib/AnyEvent/Campfire.pm view on Meta::CPAN
package AnyEvent::Campfire;
{
$AnyEvent::Campfire::VERSION = '0.0.3';
}
# Abstract: Base class of `AnyEvent::Campfire::*`
use Moose;
use namespace::autoclean;
use MIME::Base64;
has 'rooms' => ( is => 'rw' );
has 'token' => (
is => 'rw',
isa => 'Str',
);
has 'account' => (
is => 'ro',
isa => 'Str',
);
has 'authorization' => (
is => 'ro',
isa => 'Str',
lazy_build => 1,
);
has '_events' => (
is => 'ro',
isa => 'HashRef',
default => sub { {} },
);
sub _build_authorization {
my $auth = 'Basic ' . encode_base64( shift->token . ':x' );
$auth =~ s/\n//;
return $auth;
}
sub emit {
my ( $self, $name ) = ( shift, shift );
if ( my $s = $self->_events->{$name} ) {
for my $cb (@$s) {
$self->$cb(@_) if $cb;
}
}
return $self;
}
sub on {
my ( $self, $name, $cb ) = @_;
push @{ $self->{_events}{$name} ||= [] }, $cb;
return $cb;
}
sub BUILD {
my $self = shift;
$self->rooms( [ split( /,/, $self->rooms ) ] );
return $self;
}
__PACKAGE__->meta->make_immutable;
1;
( run in 0.608 second using v1.01-cache-2.11-cpan-39bf76dae61 )