| 1 | package YAML::YuyuPress; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | YAML::YuyuPress - Tool for making presentations out of YAML files. | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | use YAML::YuyuPress; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | my $yuyu = new YAML::YuyuPress( { path => $path, #to templates dir | ||||||||||||||||||||||||||||
| 16 | plantilla => 'plantilla.tmpl', #template | ||||||||||||||||||||||||||||
| 17 | contenido => 'contenido.yaml', #slides | ||||||||||||||||||||||||||||
| 18 | staticdir => '/path/to/dir' # static dir | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | $yuyu->run(); # Runs in port 8080 by default | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | $yuyu->port(13432); # Set the server port | ||||||||||||||||||||||||||||
| 24 | my $pid=$yuyu->background(); # or | ||||||||||||||||||||||||||||
| 25 | $yuyu->run(); # Both inherited from HTML::Server::Simple::CGI | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | The presentation can then be run from http://localhost:13432/, slides | ||||||||||||||||||||||||||||
| 28 | accessed via http://localhost:13432/?slide=1 or, REST-style, | ||||||||||||||||||||||||||||
| 29 | http://localhost:13432/slide/1, | ||||||||||||||||||||||||||||
| 30 | index via http://localhost:13432/?indice=1 or | ||||||||||||||||||||||||||||
| 31 | http://localhost:13432/index | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Program for making presentations out of YAML files. Can be used as a | ||||||||||||||||||||||||||||
| 36 | module or from the C<yuyupress> script | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | Inherits from L<YAML::Yuyu> and L<HTTP::Server::Simple::CGI> for serving pages. Use C<yuyuhowto> for a quick presentation of the things that can be done, and how to do them; the presentation itself is contained in the C<bin> directory of the distro under the name C<howto.yaml>. C<yyp-?.yaml>, in the C<t> dir, are examples also of correct presentations. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head1 METHODS | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =cut | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | our $VERSION="0.07_2"; | |||||||||||||||||||||||||||
| 45 | 2 | our ($CVSVERSION) = ( '$Revision: 1.23 $' =~ /(\d+\.\d+)/ ) ; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | use base qw/HTTP::Server::Simple::CGI/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | use HTTP::Server::Simple::Static; # for serve_static | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 2 | ▶ | use YAML::Yuyu; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head2 new | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | Creates a new copy of the object | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.2
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 59 | 1 | my ($opts ) = shift; | |||||||||||||||||||||||||||
| 60 | 1 | my $self = $class->SUPER::new(); | |||||||||||||||||||||||||||
| 61 | 1 | $self->{'staticdir'} = $opts->{'staticdir'}; | |||||||||||||||||||||||||||
| 62 | my $yuyu = YAML::Yuyu->new(path => $opts->{'path'}, | ||||||||||||||||||||||||||||
| 63 | plantilla => $opts->{'plantilla'}, | ||||||||||||||||||||||||||||
| 64 | 1 | contenido => $opts->{'contenido'} ); | |||||||||||||||||||||||||||
| 65 | 0 | $self->{'_yuyu'} = $yuyu; | |||||||||||||||||||||||||||
| 66 | 0 | return $self; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head2 handle_request CGI | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Overrides default to return the main presentation page | ||||||||||||||||||||||||||||
| 72 | ('portada'), index or any of the slides. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub handle_request { | ||||||||||||||||||||||||||
|
Subroutine
handle_request: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 0 | my ( $self, $cgi ) = @_; | |||||||||||||||||||||||||||
| 79 | 0 | my $path = $cgi->path_info(); | |||||||||||||||||||||||||||
| 80 | 0 | my $yuyu = $self->{'_yuyu'}; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ( $path ne "/" and (-e $self->{'staticdir'}."/$path") ) { # First of all, static stuff | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$path ne "/" and -e $self->{"staticdir"} . "/$path"
MC/DC0%0/2
$path ne "/" and -e $self->{"staticdir"} . "/$path"
$path ne "/"
-e $self->{"staticdir"} . "/$path"
Truth table0%0/3
A and B
A= $path ne "/"B= -e $self->{"staticdir"} . "/$path"
| |||||||||||||||||||||||||||||
| 82 | 0 | $self->serve_static( $cgi, $self->{'staticdir'}); | |||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||
| 84 | 0 | print "HTTP/1.0 200 OK\r\n", | |||||||||||||||||||||||||||
| 85 | $cgi->header(); | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ( $path eq '/' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ( !$cgi->param() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | print $yuyu->portada; | |||||||||||||||||||||||||||
| 89 | 0 | return 1; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ( $cgi->param('indice') ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | print $yuyu->indice; | |||||||||||||||||||||||||||
| 93 | 0 | return 1; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ( $cgi->param('slide') ne '' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | print $yuyu->slide( $cgi->param('slide') ); | |||||||||||||||||||||||||||
| 97 | 0 | return 1; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||
| 100 | 0 | $self->process_REST( $cgi, $path ); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub process_REST( ) { | ||||||||||||||||||||||||||
|
Subroutine
process_REST: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 106 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 107 | 0 | my $cgi = shift; | |||||||||||||||||||||||||||
| 108 | 0 | my $path = shift; | |||||||||||||||||||||||||||
| 109 | 0 | my $yuyu = $self->{'_yuyu'}; | |||||||||||||||||||||||||||
| 110 | 0 | my ($foo, $command, @args) = split("/", $path ); | |||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ( $command eq 'index' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 112 | 0 | print $yuyu->indice; | |||||||||||||||||||||||||||
| 113 | } elsif ( $command eq 'slide' ) { | ||||||||||||||||||||||||||||
| 114 | 0 | print $yuyu->slide( $args[0] ); | |||||||||||||||||||||||||||
| 115 | } else { | ||||||||||||||||||||||||||||
| 116 | 0 | print "HTTP/1.0 404 Not found\r\n"; | |||||||||||||||||||||||||||
| 117 | 0 | print $cgi->start_html('Not found'), | |||||||||||||||||||||||||||
| 118 | $cgi->h1("$path Not found"), | ||||||||||||||||||||||||||||
| 119 | $cgi->end_html; | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 Copyright | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | This file is released under the GPL. See the LICENSE file included in this distribution, | ||||||||||||||||||||||||||||
| 127 | or go to http://www.fsf.org/licenses/gpl.txt | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | CVS Info: $Date: 2008/02/11 13:04:30 $ | ||||||||||||||||||||||||||||
| 130 | $Header: /home/jmerelo/repos/yuyupress/lib/YAML/YuyuPress.pm,v 1.23 2008/02/11 13:04:30 jmerelo Exp $ | ||||||||||||||||||||||||||||
| 131 | $Author: jmerelo $ | ||||||||||||||||||||||||||||
| 132 | $Revision: 1.23 $ | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =cut | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 2 | 'Tostodo'; | |||||||||||||||||||||||||||