blib/lib/Cikl/Smrt/Broker.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 49 CC 3 SCAR 16.7
CC
3
Cov
0%
emit
12.0
_emit
2.0
BEGIN
2.0
CRAP 5.3
1 package Cikl::Smrt::Broker;
2 use strict;
3 use warnings;
4 use Mouse;
5 use namespace::autoclean;
6 use Try::Tiny;
7  
8 has 'builder' => (
9 is => 'bare',
10 isa => 'Cikl::EventBuilder',
11 reader => '_builder',
12 required => 1
13 );
14  
15 has 'count' => (
16 is => 'ro',
17 isa => 'Num',
18 writer => '_set_count',
19 required => 1,
20 default => 0,
21 init_arg => undef
22 );
23  
24 has 'count_failed' => (
25 is => 'ro',
26 isa => 'Num',
27 writer => '_set_count_failed',
28 required => 1,
29 default => 0,
30 init_arg => undef
31 );
32  
33 has 'count_too_old' => (
34 is => 'ro',
35 isa => 'Num',
36 writer => '_set_count_too_old',
37 required => 1,
38 default => 0,
39 init_arg => undef
40 );
41  
42 sub emit {
43 my $self = shift;
44 my $event_hash = shift;
45 my $err;
46 my $event;
47 try {
48 $event = $self->_builder->build_event($event_hash);
49 } catch {
50 $err = shift;
51 };
52 if ($err) {
53 $self->_set_count_failed($self->count_failed() + 1);
54 return;
55 }
56 if (defined($event)) {
57 $self->_emit($event);
58 $self->_set_count($self->count() + 1);
59 } else {
60 $self->_set_count_too_old($self->count_too_old() + 1);
61 # It was too old.
62 }
63 }
64  
65 sub _emit {
66 my $self = shift;
67 die("_emit not implemented!");
68 }
69  
70 __PACKAGE__->meta->make_immutable;
71  
72 1;