File Coverage

blib/lib/App/makebeamerinfo/Transitions.pm
Criterion Covered Total %
statement 56 56 100.0
branch 13 14 92.8
condition 3 5 60.0
subroutine 12 12 100.0
pod 0 7 0.0
total 84 94 89.3


line stmt bran cond sub pod time code
1             package App::makebeamerinfo::Transitions;
2              
3 3     3   29601 use strict;
  3         5  
  3         752  
4 3     3   16 use warnings;
  3         5  
  3         92  
5 3     3   16 use Carp;
  3         6  
  3         2409  
6              
7             #list of the available transitions
8             our @All = ( qw/
9             Crossfade
10             None
11             PagePeel PageTurn
12             SlideDown SlideLeft SlideRight SlideUp
13             SpinOutIn SpiralOutIn
14             SqueezeDown SqueezeLeft SqueezeRight SqueezeUp
15             WipeBlobs
16             WipeCenterIn WipeCenterOut
17             WipeUp WipeDown WipeLeft WipeRight
18             WipeDownRight WipeUpLeft
19             ZoomOutIn
20             / );
21              
22             sub new {
23 6     6 0 28 my $class = shift;
24 6         19 my $self = {
25             name => shift,
26             last_transition => '', # prevent repeated transitions
27             };
28 6         16 bless $self, $class;
29              
30             # handle shortcut
31 6 100       18 if ( @_ == 1 ) {
32 3         4 my $base = shift;
33 3 100       9 if ( $base eq ':none' ) {
34 1         6 push @_, frame => ':default', increment => ['None'];
35             } else {
36 2         8 push @_, frame => $base, increment => $base;
37             }
38             }
39              
40 6         22 $self->_initialize(@_);
41 6         35 return $self;
42             }
43              
44             sub _initialize {
45 6     6   8 my $self = shift;
46              
47 6         22 my %init = @_;
48              
49 6         33 for my $type ( qw/ frame increment / ) {
50              
51 12         25 my $spec = $init{$type};
52              
53 12         30 $self->{$type} = {};
54 12 100       37 next if $spec eq ':default';
55              
56 9         14 my $base = 0;
57 9 100       25 if ( $spec eq ':all' ) {
58 2         2 $base = 1;
59             }
60              
61 9         260 $self->{$type}{$_} = $base for @All;
62              
63 9 100       31 if ( ref $spec ) {
64 7         48 $self->{$type}{$_} = 1 for @$spec;
65             }
66              
67             }
68             }
69              
70             # get all selected
71              
72             sub get_selected {
73 11     11 0 19 my ($self, $type) = @_;
74 11         31 my $hash = $self->get_type($type);
75 11         96 my @keys = keys %$hash;
76 11 50       216 croak "Type $type is default" unless @keys;
77 11         20 return sort grep { $hash->{$_} } @keys;
  264         770  
78             }
79              
80             sub get_type {
81 11     11 0 18 my ($self, $type) = @_;
82 11   33     40 my $hash = $self->{$type} || croak "Unknown transition type '$type'";
83 11         22 return $hash;
84             }
85              
86             # return the contents of a random element of an array
87             sub get_random_element {
88 7     7 0 15 my $self = shift;
89 7   100     4658 my $type = shift || 'frame';
90              
91 7         25 my @array = $self->get_selected($type);
92 7         14 my $length = @array;
93              
94 7 100       306 return $array[0] if $length == 1;
95              
96 2         6 my $return = $self->{last_transition};
97              
98             # prevent repeated transitions
99 2         10 while ($return eq $self->{last_transition}) {
100 3         59 $return = $array[int rand $length];
101             }
102              
103 2         4 $self->{last_transition} = $return;
104 2         189 return $return;
105             }
106              
107             # test if default X are selected
108              
109             sub _default {
110 14     14   24 my ($self, $type) = @_;
111 14         15 return ! keys %{ $self->{$type} };
  14         116  
112             }
113              
114 10     10 0 32 sub default_frame { shift->_default('frame') }
115 4     4 0 10 sub default_increment { shift->_default('increment') }
116              
117             # ro accessors
118 5     5 0 29 sub name { $_[0]->{name} }
119              
120             1;
121