App-Greple-update

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


update - Greple module to update file content

# SYNOPSIS

greple -Mupdate

Options:

    --update       replace file content
    --with-backup  make backup files

    --diff         produce diff output
    -U#            specify unified diff context length

    --discard      simply discard the output

# VERSION

Version 1.04

README.md  view on Meta::CPAN

    **greple** behaves as normal operation, that means only matched lines
    are printed.

    File is not touched as far as its content does not change.

    The file is also not updated if the output is empty.  This is to
    prevent the contents of the file from being erased if none of the
    match strings are included.  If you want to intentionally empty a
    file, you need to think of another way.

- **--with-backup**\[=_suffix_\]

    Backup original file with `.bak` suffix.  If optional parameter is
    given, it is used as a suffix string.  If the file exists, `.bak_1`,
    `.bak_2` ... are used.

- **--discard**
- **--update::discard**

    Simply discard the command output without updating file.  This option
    can be used when the output of the command is not needed and only side

lib/App/Greple/update.pm  view on Meta::CPAN


update - Greple module to update file content

=head1 SYNOPSIS

greple -Mupdate

Options:

  --update       replace file content
  --with-backup  make backup files

  --diff         produce diff output
  -U#            specify unified diff context length

  --discard      simply discard the output

=head1 VERSION

Version 1.04

lib/App/Greple/update.pm  view on Meta::CPAN

B<greple> behaves as normal operation, that means only matched lines
are printed.

File is not touched as far as its content does not change.

The file is also not updated if the output is empty.  This is to
prevent the contents of the file from being erased if none of the
match strings are included.  If you want to intentionally empty a
file, you need to think of another way.

=item B<--with-backup>[=I<suffix>]

Backup original file with C<.bak> suffix.  If optional parameter is
given, it is used as a suffix string.  If the file exists, C<.bak_1>,
C<.bak_2> ... are used.

=item B<--discard>

=item B<--update::discard>

Simply discard the command output without updating file.  This option

lib/App/Greple/update.pm  view on Meta::CPAN

use Carp;
use Encode;
use Data::Dumper;
use App::Greple::Common;
use Text::ParseWords qw(shellwords);

our $debug = 0;
our $remember_data = 1;
our $opt_update_diffcmd = "diff -u";
our $opt_suffix = '';
our $opt_backup;
our $opt_U = '';

my $current_file;
my $contents;
my @update_diffcmd;

sub debug {
    $debug = 1;
}

sub update_initialize {
    @update_diffcmd = shellwords $opt_update_diffcmd;
    if ($opt_U ne '') {
	@update_diffcmd = ('diff', "-U$opt_U");
    }
    if (defined $opt_backup) {
	$opt_suffix = $opt_backup ne '' ? $opt_backup : '.bak';
    }
}

sub update_begin {
    my %arg = @_;
    $current_file = delete $arg{&FILELABEL} or die;
    $contents = $_ if $remember_data;
}

#

lib/App/Greple/update.pm  view on Meta::CPAN

}

1;

__DATA__

builtin diffcmd=s     $opt_update_diffcmd
builtin update-suffix=s      $opt_suffix
builtin U=i           $opt_U
builtin remember!     $remember_data
builtin with-backup:s $opt_backup

option default \
	--prologue update_initialize \
	--begin    update_begin

expand ++dump --all -h --color=never --no-newline --no-line-number
option --update::diff    ++dump --of &update_diff
option --update::create  ++dump --begin update_divert --end update_file() --update-suffix=.new
option --update::update  ++dump --begin update_divert --end update_file(replace)
option --update::discard        --begin update_divert --end update_file(discard)



( run in 1.549 second using v1.01-cache-2.11-cpan-49f99fa48dc )