CGI-Application-Util-Diff
view release on metacpan or search on metacpan
lib/CGI/Application/Util/Diff.pm view on Meta::CPAN
package CGI::Application::Util::Diff;
# Author:
# Ron Savage <ron@savage.net.au>
use base 'CGI::Application';
use strict;
use warnings;
use Algorithm::Diff qw/sdiff/;
use Carp;
use CGI::Application::Util::Diff::Actions;
use CGI::Application::Util::Diff::Config;
use Cwd; # For realpath.
use File::stat;
use HTML::Entities::Interpolate; # For %Entitize.
use HTML::Template;
use IPC::Capture;
use JSON::XS;
use Path::Class; # For dir() and cleanup().
our $VERSION = '1.03';
# -----------------------------------------------
sub build_form
{
my($self) = @_;
my($dir_action) = $self -> param('actions') -> get_dir_menu();
my(@dir_action) = map{qq|{text: "$$dir_action{$_}", value: "$_", onclick: {fn: onMenuItemClick} }|} sort keys %$dir_action;
my($file_action) = $self -> param('actions') -> get_file_menu();
my(@file_action) = map{qq|{text: "$$file_action{$_}", value: "$_", onclick: {fn: onMenuItemClick} }|} sort keys %$file_action;
# Since this is Javascript, we must add a ',' to all elements but the last.
# We cannot add a ',' to all elements, and then use this:
# substr($dir_action[$#dir_action], -1, 1) = '';
# to chop a comma off the last element, because substr() won't work with an array element as an lvalue.
for my $i (0 .. ($#dir_action - 1) )
{
$dir_action[$i] .= ',';
}
for my $i (0 .. ($#file_action - 1) )
{
$file_action[$i] .= ',';
}
# Build the form and the corresponding Javascript.
$self -> param('js') -> param(confirm_action => $self -> param('actions') -> get_confirm_action());
$self -> param('js') -> param(dir_loop => [map{ {item => $_} } @dir_action]);
$self -> param('js') -> param(file_loop => [map{ {item => $_} } @file_action]);
$self -> param('js') -> param(form_action => $self -> param('config') -> get_form_action() );
# Keep YUI happy by ensuring the HTML is one long string...
my($form) = $self -> param('form') -> output();
$form =~ s/\n//g;
$self -> log('Leaving build_form');
return ($self -> param('js') -> output(), $form);
} # End of build_form.
# -----------------------------------------------
sub cgiapp_init
{
my($self) = @_;
$self -> param(config => CGI::Application::Util::Diff::Config -> new() );
$self -> tmpl_path($self -> param('config') -> get_tmpl_path() );
$self -> param(actions => CGI::Application::Util::Diff::Actions -> new() );
$self -> param(form => $self -> load_tmpl('form.tmpl') );
$self -> param(js => $self -> load_tmpl('form.js') );
$self -> run_modes(['diff', 'initialize']);
# Connect to the database for logging.
my($logger_class, $logger_file) = split(/=/, $self -> param('config') -> get_logger() || '');
if ($logger_class)
{
my($class) = $logger_class;
$class =~ s|::|/|g;
eval qq|require "$class.pm"|;
if ($@)
{
( run in 1.270 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )