CGI-Application-Util-Diff
view release on metacpan or search on metacpan
lib/CGI/Application/Util/Diff.pm view on Meta::CPAN
}
if ($command)
{
$self -> log(qq|Running command: $command|);
# We use IPC::Capture with autochomp false so we can split the output string.
my($ipc) = IPC::Capture -> new({filter => 'all_output'});
my($result) = $ipc -> run($command);
@$output = split(/\n/, $result);
if ($action eq 'file_diff')
{
my($limit) = $self -> param('actions') -> get_max_diff_line_count();
if ($#$output >= $limit)
{
my($diff) = $#$output + 1 - $limit;
$#$output = $limit - 1;
push @$output, "Output truncated by $diff line" . ($diff == 1 ? '' : 's');
}
}
# Log before calling $Entitize{...}!
$self -> log('First few lines of output');
for my $i (0 .. ( ($#$output >= 4) ? 4 : $#$output) )
{
$self -> log($$output[$i]);
}
@$output = map{ {line => $Entitize{$_} } } @$output;
}
$self -> log("Leaving run mode 'process_action'");
return $output;
} # End of process_action.
# -----------------------------------------------
sub read_dir
{
my($self, $dir_name) = @_;
opendir(INX, $dir_name) || return ($self -> error_message(5, $dir_name), []);
my(@file_name) = readdir INX;
closedir INX;
my(%file_name);
my($name);
my($stat);
for my $file_name (@file_name)
{
$name = file($dir_name, $file_name);
$stat = stat($name);
$file_name{$file_name} =
{
mtime => scalar localtime($stat -> mtime() ),
size => $stat -> size(),
type => -d $name ? 'Dir' : 'File',
};
}
$self -> log('Leaving read_dir');
return ('', {%file_name});
} # End of read_dir.
# -----------------------------------------------
sub read_dirs
{
my($self, $left, $right) = @_;
my(@left_result) = $self -> read_dir($left);
my(@right_result) = $self -> read_dir($right);
$self -> log('Leaving read_dirs');
return ($left_result[0] || $right_result[0], $left_result[1], $right_result[1]);
} # End of read_dirs.
# -----------------------------------------------
sub remove_span
{
my($self, $s) = @_;
$s =~ s|^<span class=".+">(.+)</span>$|$1|;
return $s;
} # End of remove_span.
# -----------------------------------------------
sub teardown
{
my($self) = @_;
$self -> log('Leaving ' . __PACKAGE__);
} # End of teardown.
# -----------------------------------------------
1;
=head1 NAME
C<CGI::Application::Util::Diff> - Diff 2 directories or files, or run other commands
=head1 Synopsis
A classic CGI script:
( run in 1.230 second using v1.01-cache-2.11-cpan-39bf76dae61 )