File Coverage

blib/lib/App/EventStreamr/Ingest.pm
Criterion Covered Total %
statement 34 50 68.0
branch 4 16 25.0
condition n/a
subroutine 12 14 85.7
pod n/a
total 50 80 62.5


line stmt bran cond sub pod time code
1             package App::EventStreamr::Ingest;
2 2     2   28120 use Method::Signatures;
  2         93000  
  2         10  
3 2     2   1608 use Scalar::Util::Reftype;
  2         6368  
  2         96  
4 2     2   10 use Carp 'croak';
  2         0  
  2         64  
5 2     2   12906 use Module::Load;
  2         2384  
  2         10  
6 2     2   1114 use Moo;
  2         12492  
  2         10  
7 2     2   2764 use namespace::clean;
  2         5626  
  2         8  
8              
9             # ABSTRACT: A Ingest object
10              
11             our $VERSION = '0.3'; # VERSION: Generated by DZP::OurPkg:Version
12              
13              
14             my $ConfigRef = sub {
15             croak "config isn't a 'App::EventStreamr::Config' object!" unless reftype( $_[0] )->class eq "App::EventStreamr::Config";
16             };
17              
18             my $StatusRef = sub {
19             croak "config isn't a 'App::EventStreamr::Status' object!" unless reftype( $_[0] )->class eq "App::EventStreamr::Status";
20             };
21              
22             has 'config' => ( is => 'rw', required => 1, isa => $ConfigRef );
23             has 'status' => ( is => 'rw', required => 1, isa => $StatusRef );
24             has 'backend' => ( is => 'ro', default => sub { 'DVswitch' } );
25             has 'type' => ( is => 'ro', default => sub { 'ingest' } );
26             has 'id' => ( is => 'ro', default => sub { 'ingest' } );
27             has '_devices' => ( is => 'ro', default => sub { { } } );
28              
29 2 50   2   177968 method _load_package($device) {
  1 50   1   3  
  1         7  
  1         2  
  1         11  
30 1         12 my $pkg = "App::EventStreamr::".$self->backend."::Ingest::".$device->{type};
31 1         10 load $pkg;
32 0         0 $self->_devices->{$device->{id}} = $pkg->new(
33             device => $device->{device},
34             id => $device->{id},
35             config => $self->config,
36             status => $self->status,
37             );
38             }
39              
40              
41 2 50   2   1390 method start() {
  1     1   3581  
  1         12  
42 1         4 foreach my $device (@{$self->config->devices}) {
  1         12  
43 1 50       901 if (! defined $self->_devices->{$device->{id}}) {
44 1         7 $self->_load_package($device);
45             }
46 0           $self->_devices->{$device->{id}}->start();
47             }
48             }
49              
50              
51 2 0   2   1248 method run_stop() {
  0     0      
  0            
52 0           foreach my $device (@{$self->config->devices}) {
  0            
53 0 0         if (! defined $self->_devices->{$device->{id}}) {
54 0           $self->_load_package($device);
55             }
56 0           $self->_devices->{$device->{id}}->run_stop();
57             }
58             }
59              
60              
61 2 0   2   1172 method stop() {
  0     0      
  0            
62 0           foreach my $device (@{$self->config->devices}) {
  0            
63 0 0         if (! defined $self->_devices->{$device->{id}}) {
64 0           $self->_load_package($device);
65             }
66 0           $self->_devices->{$device->{id}}->stop();
67             }
68             }
69              
70             1;
71              
72             __END__
73              
74             =pod
75              
76             =encoding UTF-8
77              
78             =head1 NAME
79              
80             App::EventStreamr::Ingest - A Ingest object
81              
82             =head1 VERSION
83              
84             version 0.3
85              
86             =head1 SYNOPSIS
87              
88             This package provides an extendable class for starting/stopping
89             ingest devices.
90              
91             =head1 DESCRIPTION
92              
93             This package provides the core run/stop logic for Ingest Devices. A
94             backend specific package will extend this and provide any extra logic
95             specific to its needs.
96              
97             'backend' is expected to be overridden by the consuming role.
98              
99             =head1 METHODS
100              
101             =head2 start
102              
103             $ingest->start()
104              
105             Will start all configured devices.
106              
107             =head2 run_stop
108              
109             $ingest->run_stop()
110              
111             Will start all configured devices if they're intended to be running
112             or stop them if they're not.
113              
114             =head2 stop
115              
116             $ingest->stop()
117              
118             Will stop all configured devices.
119              
120             =head1 AUTHOR
121              
122             Leon Wright < techman@cpan.org >
123              
124             =head1 COPYRIGHT AND LICENSE
125              
126             This software is Copyright (c) 2014 by Leon Wright.
127              
128             This is free software, licensed under:
129              
130             The GNU Affero General Public License, Version 3, November 2007
131              
132             =cut