Yuyu.pm

filter: Statementstmt 28.4% 31 / 109 Branchbran 3.1% 1 / 32 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 56.2% 9 / 16 Podpod 42.8% 3 / 7 totaltotal 25.5% 44 / 172 CC 23 SCAR 32.2
CC
23
Cov
22%
slide
56.0
procesaItem
56.0
__ANON__
15.1
CRAP 25.0
« YuyuPress.pm ↑ Summary
1 package YAML::Yuyu;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 YAML::Yuyu - Easily create presentations from a YAML file.
11  
12 =head1 SYNOPSIS
13  
14 my $yuyu = new YAML::Yuyu( path => $path,
15 plantilla => 'plantilla.tmpl',
16 contenido => 'contenido.yaml' );
17  
18 # From an array of pre-loaded or programatically created slides
19 use YAML qw(LoadFile);
20 @slides = LoadFile('yourslides.yaml');
21 my $yuyu = new YAML::Yuyu( path => $path,
22 plantilla => 'plantilla.tmpl',
23 contenido => \@slides );
24
25 # From a glob; v. gr. data behind the __END__ marker
26 my $yuyu3 = YAML::Yuyu->new( path => $path,
27 plantilla => $plantilla,
28 contenido => \*main::DATA );
29  
30 my $nth_slide = $yuyu->slide( $n );
31 my $front_page = $yuyu->portada();
32 my $index = $yuyu->index();
33  
34 =cut
35  
36 =head1 DESCRIPTION
37  
38 Derived from L<Object::props>, which is a way cool module, this module
39 loads a YAML from which it derives a presentation: index, slides, and
40 so on. It can be used from another module, but you'll usually want to
41 do it from the scripts for standalone presentations (with its own web
42 server, no less) or to generate a single or several HTML pages you'll
43 want to present from somewhere else or upload to a website.
44  
45 =head1 USAGE
46  
47 Stand-alone presentation tool. It will use default templates, if none
48 is indicated
49  
50 bash$ yuyupress presentation.yaml [path-to-templates] [template(s)]
51  
52 Generate a web page with the presentation
53  
54 bash$ yuyugen presentation.yaml [path-to-templates] [template(s)]
55  
56 =head1 METHODS
57  
58 =cut
59  
60 3 ▶use YAML qw(LoadFile Load); # Para configuración
Subroutine BEGIN: called CC=1 SCAR=0.0
61 3 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 3 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 3 our ($CVSVERSION) = ( '$Revision: 1.15 $' =~ /(\d+\.\d+)/ ) ;
65  
66 #Declaración de propiedades
67 3 ▶use Object::props qw( path plantilla contenido );
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 3 ▶use Class::constr {
Subroutine BEGIN: called CC=1 SCAR=2.5
70 2 ▶ init => sub {
Subroutine __ANON__: called CC=5 SCAR=27.1
71 2 my $template = Template->new( {INCLUDE_PATH => $_[0]->path } );
72 2 $_[0]->{_template} = $template;
73 2 my @stream;
74 2 ▶ if ( ref $_[0]->contenido eq '' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $_[0]->contenido eq '') { } 2 0 2
elsif (ref $_[0]->contenido eq 'ARRAY') { } 0 0 0
elsif (ref $_[0]->contenido eq 'GLOB') { } 0 0 0
75 2 @stream = LoadFile( $_[0]->contenido );
76 } elsif ( ref $_[0]->contenido eq 'ARRAY' ) {
77 0 @stream = @{$_[0]->contenido};
78 } elsif ( ref $_[0]->contenido eq 'GLOB' ) {
79 0 my $glob = $_[0]->contenido;
80 0 my $stream = join('',<$glob>);
81 0 @stream = Load($stream);
82 }
83 0 ▶ carp "Bad content stream" if !@stream;
Branch: 1 branch
BranchTrueFalseTotal
unless @stream 0 0 0
84 0 $_[0]->{_portada} = shift @stream;
85 0 $_[0]->{_slides} = \@stream;
86 0 $_[0]->{_doc} = $_[0]->plantilla;
87 0 $_[0]->{_size } = scalar @stream - 1;
88 }
89 3 };
90  
91 =head2 portada
92  
93 C<portada> is the main page; it returns the title and general front matter for the presentation
94  
95 =cut
96  
97 0 ▶sub portada {
Subroutine portada: not called CC=2 SCAR=17.9
Pod documented
98 0 my $self = shift;
99 0 my %data = %{$self->{_portada}->[0]};
100 0 my $contenido=<<EIF;
101 <h2>$data{'autor'}</h2>
102  
103 <var>$data{'email'}</var>
104  
105 <h3>$data{'sitio'}</h3>
106  
107 <div style='margin:0 auto'><a href='?slide=0'>Comienzo</a></div>
108 EIF
109 0 my $salida;
110 $self->{_template}->process( $self->plantilla,
111 { titulo => $data{'titulo'},
112 contenido => $contenido },
113 \$salida )
114 0 ▶ || die $self->{_template}->error(), "\n"; ;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_template"}->process($self->plantilla, {"titulo", $data{"titulo"}, "contenido", $contenido}, \$salida) or die $self->{"_template"}->error, "\n" 0 0 0
115 0 return $salida;
116 }
117  
118  
119 =head2 slide
120  
121 C<slide>( $slide_number) returns the $slide_number'th slide from the presentation
122  
123 =cut
124  
125 0 ▶sub slide {
Subroutine slide: not called CC=7 SCAR=40.3
Pod documented
126 0 my $self = shift;
127 0 ▶ my $nr = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
128 0 ▶ die if ($nr > $self->{_size}) || ($nr < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $nr > $self->{"_size"} or $nr < 0 0 0 0
Condition0%0/3
$nr > $self->{"_size"} or $nr < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$nr > $self->{"_size"} or $nr < 0
$nr > $self->{"_size"} $nr < 0
Truth table0%0/3
A or B
A= $nr > $self->{"_size"}B= $nr < 0
ABresult
1X1
011
000
129 0 my @slide = @{$self->{_slides}[$nr]};
130 0 my $salida;
131 0 my $titulo = shift @slide;
132 0 my $contenido;
133 0 $contenido = procesa(\@slide );
134 0 my $navegacion;
135 0 ▶ if ( $nr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nr) 0 0 0
136 0 $navegacion .= "<a href='?slide=".($nr-1)."'>Anterior</a> ";
137 }
138 0 $navegacion .= "<a href='?indice=1'>Índice</a> ";
139 0 ▶ if ( $nr < $self->{_size} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nr < $self->{"_size"}) 0 0 0
140 0 $navegacion .= "<a href='?slide=".($nr+1)."'>Siguiente</a> ";
141 }
142 $self->{_template}->process( $self->plantilla,
143 { titulo => $titulo,
144 contenido => $contenido,
145 navegacion => $navegacion,
146 number => $nr+1
147 },
148 \$salida )
149 0 ▶ || die $self->{_template}->error(), "\n"; ;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_template"}->process($self->plantilla, {"titulo", $titulo, "contenido", $contenido, "navegacion", $navegacion, "number", $nr + 1}, \$salida) or die $self->{"_template"}->error, "\n" 0 0 0
150 0 return $salida;
151 };
152  
153 =head2 indice
154  
155 Returns the presentation index
156  
157 =cut
158  
159 0 ▶sub indice {
Subroutine indice: not called CC=2 SCAR=17.9
Pod documented
160 0 my $self = shift;
161 0 my $i;
162 my $contenido="<ol>".
163 join("\n",
164 0 map("<li><a href='?slide=".$i++."'>".$_->[0]."</a></li>", @{$self->{_slides}} ) )."</ol>";
165
166 0 my $salida;
167 $self->{_template}->process( $self->plantilla,
168 { titulo => 'Indice',
169 contenido => $contenido
170 },
171 \$salida )
172 0 ▶ || die $self->{_template}->error(), "\n"; ;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_template"}->process($self->plantilla, {"titulo", "Indice", "contenido", $contenido}, \$salida) or die $self->{"_template"}->error, "\n" 0 0 0
173 0 return $salida;
174 }
175  
176  
177 0 ▶sub procesa {
Subroutine procesa: not called CC=2 SCAR=17.9
Pod undocumented
178 0 my $yref = shift;
179 0 my $contenido='';
180 0 ▶ if (@$yref > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$yref > 0) { } 0 0 0
181 0 $contenido = "<ul>".procesaArray( $yref )."</ul>";
182 } else {
183 0 $contenido = procesaItem( $yref );
184 }
185 0 return $contenido;
186 }
187  
188 0 ▶sub procesaArray {
Subroutine procesaArray: not called CC=2 SCAR=17.9
Pod undocumented
189 0 my $yref = shift;
190 0 my $contenido='';
191 0 for ( @$yref ) {
192 0 $contenido .= procesaItem( $_ )."\n";
193 }
194 0 return $contenido;
195 }
196  
197 0 ▶sub procesaHash {
Subroutine procesaHash: not called CC=3 SCAR=24.8
Pod undocumented
198 0 my $yref = shift;
199 0 my $contenido='<LI><dl>';
200 0 for ( keys %$yref ) {
201 0 $contenido .= "<dt>$_</dt><dd>\n";
202 0 for my $i ( @{$yref->{$_}} ) {
203 0 $contenido .= procesaItem( $i );
204 }
205 0 $contenido .="\n</dd>";
206 }
207 0 $contenido .= "</dl></li>";
208 0 return $contenido;
209 }
210  
211 0 ▶sub procesaItem {
Subroutine procesaItem: not called CC=7 SCAR=40.3
Pod undocumented
212 0 my $yref = shift;
213 0 my $contenido='';
214 0 ▶ if ( ref $yref eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $yref eq '') { } 0 0 0
215 0 $contenido.= "<li>$yref</li>";
216 } else {
217 0 my $tag = ref $yref;
218 0 ▶ if ( $tag eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tag eq 'ARRAY') { } 0 0 0
elsif ($tag eq 'HASH') { } 0 0 0
219 0 $contenido = procesaArray( $yref );
220 } elsif ( $tag eq 'HASH' ) {
221 0 $contenido = procesaHash( $yref );
222 } else {
223 0 $contenido = "<$tag";
224 0 for ( keys %$yref ) {
225 0 ▶ if ( $_ ne 'body' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ ne "body") 0 0 0
226 0 $contenido .= " $_='$yref->{$_}'";
227 }
228 }
229 0 ▶ if ( $yref->{'body'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yref->{'body'}) { } 0 0 0
230 0 $contenido.=">".$yref->{'body'}."</$tag>";
231 } else {
232 0 $contenido.=">";
233 }
234 }
235 }
236 0 return $contenido;
237 }
238  
239 =head1 Copyright
240  
241 This file is released under the GPL. See the LICENSE file included in this distribution,
242 or go to http://www.fsf.org/licenses/gpl.txt
243  
244 CVS Info: $Date: 2008/02/11 13:03:55 $
245 $Header: /home/jmerelo/repos/yuyupress/lib/YAML/Yuyu.pm,v 1.15 2008/02/11 13:03:55 jmerelo Exp $
246 $Author: jmerelo $
247 $Revision: 1.15 $
248  
249 =cut
250  
251  
252 3 'Sacabó';
« YuyuPress.pm ↑ Summary