lib/Video/PlaybackMachine/FillProducer/RandomStillFrame.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 56 CC 3 SCAR 16.1
CC
3
Cov
0%
get_frames
12.0
is_available
2.0
start
2.0
CRAP 5.0
1 package Video::PlaybackMachine::FillProducer::RandomStillFrame;
2  
3 our $VERSION = '0.09'; # VERSION
4  
5 ####
6 #### Video::PlaybackMachine::FillProducer::RandomStillFrame
7 ####
8 #### $Revision$
9 ####
10 #### Plays a randomly-chosen still frame from a directory.
11 ####
12 #### Has, at least for now, been superseded by the SlideShow fill
13 #### producer.
14 ####
15  
16 use strict;
17 use warnings;
18 use Carp;
19  
20 with 'Video::PlaybackMachine::FillProducer';
21  
22 use POE;
23  
24 use IO::Dir;
25  
26 ############################# Class Constants ############################
27  
28 ############################## Class Methods ##############################
29  
30 ##
31 ## new()
32 ##
33 ## Arguments: (hash)
34 ## directory => string -- Directory containing images to display
35 ## time => int -- time in seconds image should be displayed
36 ##
37  
38 has 'directory' => ( 'is' => 'ro', required => 1 );
39  
40 ############################# Object Methods ##############################
41  
42  
43 sub is_available {
44 my $self = shift;
45  
46 -d $self->directory() or return;
47 $self->get_frames() >= 1 or return;
48 return 1;
49  
50 }
51  
52 sub get_frames {
53 my $self = shift;
54  
55 my $dh = IO::Dir->new( $self->directory() );
56 my @frames = ();
57 while ( my $file = $dh->read() ) {
58 next if $file =~ /^\./;
59 next unless -f "$self->{'directory'}/$file";
60 push(@frames, "$self->{'directory'}/$file");
61 }
62 return @frames;
63 }
64  
65  
66 ##
67 ## start()
68 ##
69 ## Displays a random still frame for the appropriate time. Assumes that
70 ## it's being called within a POE session.
71 ##
72 sub start {
73 my $self = shift;
74  
75 my @frames = $self->get_frames();
76 my $frame = $frames[ rand( scalar @frames ) ];
77  
78 $poe_kernel->yield('still_ready', $frame, $self->get_time_layout()->min_time());
79 }
80  
81 1;