lib/Video/PlaybackMachine/TimeLayout/GranularTimeLayout.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 48 CC 2 SCAR 10.6
CC
2
Cov
0%
get_num_events
6.0
BUILDARGS
2.0
min_time
2.0
CRAP 2.9
1 package Video::PlaybackMachine::TimeLayout::GranularTimeLayout;
2  
3 our $VERSION = '0.09'; # VERSION
4  
5 ####
6 #### Video::PlaybackMachine::TimeLayout::GranularTimeLayout
7 ####
8 #### $Revision$
9 ####
10 #### A granular time layout is for producers like slide shows. A slide
11 #### show that shows a slide for 5 seconds can fill 5, 10, 15
12 #### etc. seconds, but can't fill 12.
13 ####
14  
15 use Moo;
16  
17 use Carp;
18 use POSIX 'floor';
19  
20 has 'time' => ( is => 'ro', required => 1 );
21  
22 has 'max_iterations' => ( is => 'ro' );
23  
24 ############################# Class Constants #############################
25  
26 ############################## Class Methods ##############################
27  
28 ##
29 ## new()
30 ##
31 ## Arguments:
32 ## TIME: int -- Time per repeating event
33 ##
34 sub BUILDARGS {
35 my $type = shift;
36 my ($time, $max_iterations) = @_;
37  
38 return {
39 time => $time,
40 max_iterations => $max_iterations
41 };
42
43 }
44  
45  
46 ############################# Object Methods ##############################
47  
48 ##
49 ## min_time()
50 ##
51 ## Returns the minimum amount of time the fill can take. In this case,
52 ## returns the grain.
53 ##
54 sub min_time {
55 my $self = shift;
56
57 return $self->time();
58 }
59  
60 ##
61 ## preferred_time()
62 ##
63 ## Arguments:
64 ## TIME_LEFT
65 ##
66 ## Returns time for the number of granular events which can fit into
67 ## TIME_LEFT. If max_iterations was defined, returns the time for that
68 ## number of granular events.
69 ##
70 sub preferred_time {
71 my $self = shift;
72 my ($time_left) = @_;
73  
74 my $req_events = floor( $time_left / $self->time() );
75  
76 return $self->get_num_events($req_events) * $self->time();
77 }
78  
79 sub get_num_events {
80 my $self = shift;
81 my ($events) = @_;
82  
83 if (defined $self->max_iterations() &&
84 $events > $self->max_iterations) {
85 return $self->max_iterations();
86 }
87 else {
88 return $events;
89 }
90  
91 }
92  
93 no Moo;
94  
95 1;