App-Plog

 view release on metacpan or  search on metacpan

lib/App/Plog.pm  view on Meta::CPAN


## no critic (Modules::ProhibitMultiplePackages)
## no critic (BuiltinFunctions::ProhibitStringyEval)
## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars) 

package main ;

use strict;
use warnings ;
use Carp qw(carp croak confess) ;
use English qw( -no_match_vars ) ;
use Readonly ;

sub run_ipc3
{	
my ($command, $error_message) = @_ ;

Readonly my $CHILD_ERROR_SHIFT => 8 ;

use IPC::Open3 ;
use Symbol 'gensym'; 

my($in, $out, $err) ;
$err = gensym() ;

my $pid = open3($in, $out, $err, $command) ;
waitpid( $pid, 0 );

if ($CHILD_ERROR >> $CHILD_ERROR_SHIFT)
	{
	croak "Error: can't execute '$command' $error_message: $CHILD_ERROR\n" ;
	}

# todo: check wantarray
my $text = do { local $INPUT_RECORD_SEPARATOR = undef ; <$out> ; } ;

return $text ;
}

package App::Plog ;

use strict;
use warnings ;
use Carp qw(carp croak confess) ;

BEGIN 
{
use Sub::Exporter -setup => 
	{
	exports => [ qw() ],
	groups  => 
		{
		all  => [ qw() ],
		}
	};
	
use vars qw ($VERSION);
$VERSION     = '0.01';
}

#-------------------------------------------------------------------------------

use English qw( -no_match_vars ) ;
use Readonly ;
Readonly my $EMPTY_STRING => q{} ;

use File::HomeDir ;
use Getopt::Long ;
use English qw( -no_match_vars ) ;
use File::Temp qw/tempdir/ ;
use File::Path ;
use File::Copy::Recursive qw/rcopy/ ;

#-------------------------------------------------------------------------------

=head1 NAME

App::Plog - The one and a half minute blog

=head1 SYNOPSIS

 use App::Plog ;
 
 App::Plog::create_blog(@ARGV) ;
 
 exit(0)  ;

=head1 DESCRIPTION

Generate a rudimentary HTML blog.

=head1 DOCUMENTATION

This module installs a script that allow you to generate a rudimentary blog using your prefered editor and the command line. 
This file documents the inner workings of the module.

lib/App/Plog.pm  view on Meta::CPAN


my $class = ref($invocant) || $invocant ;
confess 'Invalid constructor call!' unless defined $class ;

my $ascii_doc_version = `asciidoc --version` ;
unless($ascii_doc_version =~ s/^.*(asciidoc \d\.\d.*)/$1/)
	{
	$ascii_doc_version = undef ;
	}

my $object = {%{$options}, ascii_doc_version => $ascii_doc_version} ;

return bless $object, $class ;
}

#-------------------------------------------------------------------------------

sub render
{

=head2 render($self, $blog_directory, $temporary_directory, $version, $commit, $text, $date)

I<Arguments>

=over 2 

=item * $self - 

=item * $blog_directory - the path to the blog directory

=item * $temporary_directory - directory where temporary data can be saved

=item * $version - number - the version  of the blog entry

=item * $commit - the commit id of the blog entry

=item * $text - the text of the entry as it was found by the version control system

=item * $date - string in format "2009-10-05 14:53:24 +0200"

=back

I<Returns> - the asciidoc text rendered to HTML

I<Exceptions> - None

=cut

my ($self, $blog_directory, $temporary_directory, $version, $commit, $text, $date) = @_ ;

my $date_html = $self->get_entry_date_html($date) ;

my $version_html = $version > 1 ? "<br> version: $version" : $EMPTY_STRING ;

my ($entry_html, $reader, $writer) = (q{Error: App::Plog::Renderer::HTML::Asciidoc can't run command 'asciidoc'!}) ;

if (defined $self->{ascii_doc_version})
	{
	my $pid = open2($reader, $writer, 'asciidoc -o - -s -' );

	local $INPUT_RECORD_SEPARATOR = undef ;
	print {$writer} $text ; close $writer ;
	$entry_html = <$reader>; close $reader ;
	}

	$entry_html = <<"EOE" ;
	<tr>
	  <td width="100" valign="top"> <font size="1"> <br> $date_html $version_html </td>
	  <td></td>
	  <td width="540"> 
		  <a name = '$commit'> </a>
		  $entry_html 
	  </td>
	</tr>
	<td><hr></td><td><hr></td><td><hr></td>

EOE
	
return $entry_html ;
}

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------

package App::Plog::Aggregator::Template::Inline ;

=head1 App::Plog::Aggregator::Template::Inline SUBROUTINES/METHODS

=cut

use strict;
use warnings ;
use Carp qw(carp croak confess) ;
use File::Slurp ;

sub new
{

=head2 new(\%options)

I<Arguments>

=over 2 

=item * \%options - the B<aggregator> section from the blog configuration file

=back

I<Returns> - an App::Plog::Aggregator::Template::Inline object

I<Exceptions> -None

=cut

my ($invocant, $options) = @_ ;

my $class = ref($invocant) || $invocant ;
confess 'Invalid constructor call!' unless defined $class ;

my $object = {%{$options}} ;



( run in 0.928 second using v1.01-cache-2.11-cpan-f56aa216473 )