Hubot/EventEmitter.pm

filter: Statementstmt 55.0% 11 / 20 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 50.0% 16 / 32 CC 4 SCAR 18.5
CC
4
Cov
46%
emit
12.0
on
6.0
BEGIN
1.0
CRAP 6.4
« Hubot/Scripts/tweet.pm ↑ Summary Hubot/Robot.pm »
1 package Hubot::EventEmitter;
2 6 $Hubot::EventEmitter::VERSION = '0.2.8';
3 6 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 ▶has 'events' => ( is => 'rw', isa => 'HashRef', default => sub { {} }, );
Subroutine __ANON__: called CC=1 SCAR=0.0
7  
8 0 ▶sub emit {
Subroutine emit: not called CC=3 SCAR=24.8
Pod documented
9 0 my ( $self, $name ) = ( shift, shift );
10 0 ▶ if ( my $s = $self->events->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $s = $self->events->{$name}) 0 0 0
11 0 for my $cb (@$s) { $self->$cb(@_) }
12 }
13 0 return $self;
14 }
15  
16 0 ▶sub on {
Subroutine on: not called CC=2 SCAR=17.9
Pod documented
17 0 my ( $self, $name, $cb ) = @_;
18 0 ▶ push @{ $self->{events}{$name} ||= [] }, $cb;
Condition0%0/2
$self->{"events"}{$name} ||= []
l!l
00
MC/DC0%0/1
$self->{"events"}{$name} ||= []
$self->{"events"}{$name}
Truth table0%0/2
A
A= $self->{"events"}{$name}
Aresult
11
00
19 0 return $cb;
20 }
21  
22 6 __PACKAGE__->meta->make_immutable;
23  
24 6 1;
25  
26 =pod
27  
28 =encoding utf-8
29  
30 =head1 NAME
31  
32 Hubot::EventEmitter
33  
34 =head1 VERSION
35  
36 version 0.2.8
37  
38 =head1 SYNOPSIS
39  
40 package Foo;
41 use Moose;
42 extends 'Hubot::EventEmitter';
43  
44 package main;
45 my $foo = Foo->new;
46 $foo->on(
47 'event1',
48 sub {
49 my ($e, @args) = @_; # $e is event emitter. ignore.
50 print "@args\n"; # 1 2 3 4
51 }
52 );
53  
54 $foo->emit('event1', 1, 2, 3, 4);
55  
56 =head1 DESCRIPTION
57  
58 subscribe event via C<on> then execute callback via C<emit>.
59  
60 =head1 METHODS
61  
62 =head2 on
63  
64 args - C<event-name>, C<callback>
65  
66 =head2 emit
67  
68 args - C<event-name>, C<@arg-pass-to-callback>
69  
70 =head1 AUTHOR
71  
72 Hyungsuk Hong <hshong@perl.kr>
73  
74 =head1 COPYRIGHT AND LICENSE
75  
76 This software is copyright (c) 2012 by Hyungsuk Hong.
77  
78 This is free software; you can redistribute it and/or modify it under
79 the same terms as the Perl 5 programming language system itself.
80  
81 =cut
« Hubot/Scripts/tweet.pm ↑ Summary Hubot/Robot.pm »