« lib/Video/PlaybackMachine/Filler.pm
↑ Summary
lib/Video/PlaybackMachine/FillProducer/RandomStillFrame.pm »
| 1 | package Video::PlaybackMachine::ScheduleTable::DB; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | our $VERSION = '0.09'; # VERSION | ||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | #### | ||||||||||||||||||||||||||||||||||||||
| 6 | #### Video::PlaybackMachine::ScheduleTable::DB | ||||||||||||||||||||||||||||||||||||||
| 7 | #### | ||||||||||||||||||||||||||||||||||||||
| 8 | #### This module is used to access the ScheduleTable. | ||||||||||||||||||||||||||||||||||||||
| 9 | #### | ||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Video::PlaybackMachine::Config; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Video::PlaybackMachine::DB; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | ############################## Class Methods ####################################### | ||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | ## | ||||||||||||||||||||||||||||||||||||||
| 21 | ## new() | ||||||||||||||||||||||||||||||||||||||
| 22 | ## | ||||||||||||||||||||||||||||||||||||||
| 23 | ## Creates a new ScheduleTable::DB object. | ||||||||||||||||||||||||||||||||||||||
| 24 | ## | ||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $type = shift; | |||||||||||||||||||||||||||||||||||||
| 27 | 0 | my (%in) = @_; | |||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||
| 29 | my $self = { | ||||||||||||||||||||||||||||||||||||||
| 30 | schedule_name => $in{'schedule_name'} // Video::PlaybackMachine::Config->config->schedule(), | ||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | schema => $in{'schema'} // Video::PlaybackMachine::DB->schema(), | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$in{"schedule_name"} // "Video::PlaybackMachine::Config"->config->schedule
$in{"schema"} // "Video::PlaybackMachine::DB"->schema
MC/DC0%0/2
$in{"schedule_name"} // "Video::PlaybackMachine::Config"->config->schedule
$in{"schedule_name"}
"Video::PlaybackMachine::Config"->config->schedule
MC/DC0%0/2
$in{"schema"} // "Video::PlaybackMachine::DB"->schema
$in{"schema"}
"Video::PlaybackMachine::DB"->schema
Truth table0%0/3
A // B
A= $in{"schedule_name"}B= "Video::PlaybackMachine::Config"->config->schedule
Truth table0%0/3
A // B
A= $in{"schema"}B= "Video::PlaybackMachine::DB"->schema
| |||||||||||||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||||||||||||
| 33 | 0 | bless $self, $type; | |||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||
| 36 | has 'schedule_name' => ( is => 'ro' ); | ||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||
| 38 | has 'schema' => ( is => 'lazy' ); | ||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub _build_schema { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_schema: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||
| 43 | 0 | return Video::PlaybackMachine::DB->schema(); | |||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | ############################## Object Methods ###################################### | ||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub getDbh { return Video::PlaybackMachine::DB->db(); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
getDbh: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | ## | ||||||||||||||||||||||||||||||||||||||
| 51 | ## get_entries_between() | ||||||||||||||||||||||||||||||||||||||
| 52 | ## | ||||||||||||||||||||||||||||||||||||||
| 53 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||
| 54 | ## BEGIN_TIME: scalar -- UNIX raw time | ||||||||||||||||||||||||||||||||||||||
| 55 | ## END_TIME: scalar -- UNIX raw time | ||||||||||||||||||||||||||||||||||||||
| 56 | ## | ||||||||||||||||||||||||||||||||||||||
| 57 | ## Returns all entries which start or end between BEGIN_TIME and END_TIME. | ||||||||||||||||||||||||||||||||||||||
| 58 | ## | ||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub get_entries_between { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_entries_between: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ( $begin_time, $end_time ) = @_; | |||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $schema = $self->schema(); | |||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | my $entries_rs = $schema->resultset('ScheduleEntry')->search( | ||||||||||||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||||||||||||
| 67 | [ | ||||||||||||||||||||||||||||||||||||||
| 68 | { 'start_time' => { '>', $begin_time } }, | ||||||||||||||||||||||||||||||||||||||
| 69 | { 'stop_time' => { '>', $begin_time } }, | ||||||||||||||||||||||||||||||||||||||
| 70 | ], | ||||||||||||||||||||||||||||||||||||||
| 71 | 'start_time' => { '<', $end_time }, | ||||||||||||||||||||||||||||||||||||||
| 72 | 0 | 'schedule' => $self->{'schedule_name'} | |||||||||||||||||||||||||||||||||||||
| 73 | }, | ||||||||||||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||||||||||||
| 75 | 'order_by' => 'start_time', | ||||||||||||||||||||||||||||||||||||||
| 76 | join => 'schedule_entry_end' | ||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return $entries_rs->all(); | |||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | ## | ||||||||||||||||||||||||||||||||||||||
| 85 | ## get_entries_after() | ||||||||||||||||||||||||||||||||||||||
| 86 | ## | ||||||||||||||||||||||||||||||||||||||
| 87 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||
| 88 | ## TIME: scalar -- UNIX raw time | ||||||||||||||||||||||||||||||||||||||
| 89 | ## NUM_ENTRIES: int -- number of entries afterwards | ||||||||||||||||||||||||||||||||||||||
| 90 | ## | ||||||||||||||||||||||||||||||||||||||
| 91 | ## Returns all entries which start after a given time. In scalar context, | ||||||||||||||||||||||||||||||||||||||
| 92 | ## returns the first entry after the given time. Returns undef if nothing left. | ||||||||||||||||||||||||||||||||||||||
| 93 | ## | ||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub get_entries_after { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_entries_after: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 96 | 0 | my ( $time, $num_entries ) = @_; | |||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | defined $num_entries | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 99 | or $num_entries = 1; | ||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | # Get next content_schedule entry | ||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $schema = $self->schema(); | |||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $entries_rs = $schema->resultset('ScheduleEntry')->search( | |||||||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||||||||
| 107 | 'start_time' => { '>', $time }, | ||||||||||||||||||||||||||||||||||||||
| 108 | 'schedule.name' => $self->schedule_name(), | ||||||||||||||||||||||||||||||||||||||
| 109 | }, | ||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||
| 111 | 'limit' => $num_entries, | ||||||||||||||||||||||||||||||||||||||
| 112 | 'order_by' => 'start_time', | ||||||||||||||||||||||||||||||||||||||
| 113 | 'join' => 'schedule' | ||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||
| 115 | ); | ||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return $entries_rs->all(); | |||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||
| 120 | else { | ||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return $entries_rs->first(); | |||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||
| 125 | ## | ||||||||||||||||||||||||||||||||||||||
| 126 | ## get_entry_during() | ||||||||||||||||||||||||||||||||||||||
| 127 | ## | ||||||||||||||||||||||||||||||||||||||
| 128 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||
| 129 | ## TIME: scalar -- UNIX raw time | ||||||||||||||||||||||||||||||||||||||
| 130 | ## | ||||||||||||||||||||||||||||||||||||||
| 131 | ## Returns the schedule entry in which TIME takes place. | ||||||||||||||||||||||||||||||||||||||
| 132 | ## Returns an empty list / undef if there is no scheduled program taking place | ||||||||||||||||||||||||||||||||||||||
| 133 | ## at the given time. | ||||||||||||||||||||||||||||||||||||||
| 134 | ## | ||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub get_entry_during { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_entry_during: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 137 | 0 | my ($time) = @_; | |||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | 0 | return $self->schema()->resultset('ScheduleEntry') | |||||||||||||||||||||||||||||||||||||
| 140 | ->find( | ||||||||||||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||||||||||||
| 142 | 'schedule.name' => $self->schedule_name(), | ||||||||||||||||||||||||||||||||||||||
| 143 | 'start_time' => { '>=', $time }, | ||||||||||||||||||||||||||||||||||||||
| 144 | 'schedule_entry_end.stop_time' => { '<', $time } | ||||||||||||||||||||||||||||||||||||||
| 145 | }, | ||||||||||||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||||||||||||
| 147 | 'join' => ['schedule_entry_end', 'schedule'] | ||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||
| 149 | ); | ||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||
| 153 | ## | ||||||||||||||||||||||||||||||||||||||
| 154 | ## get_first_entry() | ||||||||||||||||||||||||||||||||||||||
| 155 | ## | ||||||||||||||||||||||||||||||||||||||
| 156 | ## Returns: | ||||||||||||||||||||||||||||||||||||||
| 157 | ## First entry in schedule table | ||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub get_first_entry { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_first_entry: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||
| 161 | 0 | return $self->schema()->resultset('ScheduleEntry') | |||||||||||||||||||||||||||||||||||||
| 162 | ->search({ | ||||||||||||||||||||||||||||||||||||||
| 163 | 'schedule.name' => $self->schedule_name() | ||||||||||||||||||||||||||||||||||||||
| 164 | }, | ||||||||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||||||||
| 166 | 'join' => 'schedule', | ||||||||||||||||||||||||||||||||||||||
| 167 | 'order_by' => 'start_time' | ||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||
| 169 | )->first(); | ||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||
| 172 | 1; | ||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||
| 174 | 3 | ▶ | no Moo; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||
| 176 | __END__ | ||||||||||||||||||||||||||||||||||||||