| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::EventStreamr::Ingest; | 
| 2 | 2 |  |  | 2 |  | 35024 | use Method::Signatures; | 
|  | 2 |  |  |  |  | 99476 |  | 
|  | 2 |  |  |  |  | 10 |  | 
| 3 | 2 |  |  | 2 |  | 2346 | use Scalar::Util::Reftype; | 
|  | 2 |  |  |  |  | 11456 |  | 
|  | 2 |  |  |  |  | 174 |  | 
| 4 | 2 |  |  | 2 |  | 24 | use Carp 'croak'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 104 |  | 
| 5 | 2 |  |  | 2 |  | 4826 | use Module::Load; | 
|  | 2 |  |  |  |  | 2590 |  | 
|  | 2 |  |  |  |  | 18 |  | 
| 6 | 2 |  |  | 2 |  | 1154 | use Moo; | 
|  | 2 |  |  |  |  | 14768 |  | 
|  | 2 |  |  |  |  | 8 |  | 
| 7 | 2 |  |  | 2 |  | 2798 | use namespace::clean; | 
|  | 2 |  |  |  |  | 7854 |  | 
|  | 2 |  |  |  |  | 12 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | # ABSTRACT: A Ingest object | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | our $VERSION = '0.4'; # 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 |  | 213920 | method _load_package($device) { | 
|  | 1 | 50 |  | 1 |  | 3 |  | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 30 | 1 |  |  |  |  | 5 | my $pkg = "App::EventStreamr::".$self->backend."::Ingest::".$device->{type}; | 
| 31 | 1 |  |  |  |  | 9 | 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 |  | 1174 | method start() { | 
|  | 1 |  |  | 1 |  | 2132 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 42 | 1 |  |  |  |  | 3 | foreach my $device (@{$self->config->devices}) { | 
|  | 1 |  |  |  |  | 4 |  | 
| 43 | 1 | 50 |  |  |  | 448 | if (! defined $self->_devices->{$device->{id}}) { | 
| 44 | 1 |  |  |  |  | 3 | $self->_load_package($device); | 
| 45 |  |  |  |  |  |  | } | 
| 46 | 0 |  |  |  |  |  | $self->_devices->{$device->{id}}->start(); | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 2 | 0 |  | 2 |  | 870 | 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 |  | 972 | 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.4 | 
| 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 |