App-Greple-subst

 view release on metacpan or  search on metacpan

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


sub debug {
    $debug = 1;
}

sub subst_initialize {

    state $once_called++ and return;

    if ($opt_show_dictdir) {
	say "$ENV{GREPLE_SUBST_DICT}";
	exit;
    }

    Getopt::EX::LabeledParam
	->new(HASH => \%opt_stat_item)
	->load_params(@opt_stat_item);

    @opt_format = @default_opt_format if @opt_format == 0;

    $ignorechar_re = $opt_ignore_space ? qr/\s+/ : qr/\R+/;

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

    for my $show_list (@show_list) {
	my($dict, $show) = @{$show_list};
	next if @$show == 0;
	my $dict_format = ">>> %s <<<\n";
	if ($opt_stat_item{dict}) {
	    print colorize('000/L24E', sprintf($dict_format, $dict->NAME));
	}
	for my $item (@$show) {
	    my($i, $p, $hash) = @$item;
	    if ($p->is_comment) {
		say $p->comment if $opt_show_comment;
		next;
	    }
	    my($from_re, $to) = ($p->string, $p->correct // '');
	    my @keys = keys %{$hash};
	    if ($opt_stat_style eq 'dict') {
		vprintf("%-${from_max}s // %s", $from_re // '', $to // '');
	    } else {
		my @ng = sort { $hash->{$b} <=> $hash->{$a} } grep { $_ ne $to } @keys
		    if $opt_stat_item{ng};
		my @ok = grep { $_ eq $to } @keys

lib/App/Greple/subst/Dict.pm  view on Meta::CPAN

	    $obj->read_fh($fh);
	}
	$obj;
    }

    sub read_file {
	my $obj = shift or die;
	my $file = shift;
	$obj->FILE($file);
	$obj->NAME($file =~ s[.*/][]r);
	say $file if $obj->CONFIG->{dictname};
	open my $fh, "<", $file or die "$file: $!\n";
	$obj->read_fh($fh);
	$obj;
    }

    use App::Greple::Pattern;

    sub read_fh {
	my $obj = shift or die;
	my $conf = $obj->CONFIG;
	my $fh = shift;
	local $_;
	my $flag = FLAG_REGEX;
	$flag |= FLAG_COOK if $conf->{linefold};
	while (<$fh>) {
	    s/\R\z//;
	    say if $conf->{printdict};
	    if (not /^\s*[^#]/) {
		$obj->add_comment($_);
		next;
	    }
	    if (/^\Q(?(DEFINE)(?<\E(?<name>[^>]+)/) {
		$obj->{DEFINE}->{$+{name}} = $_;
		$obj->add_comment($_);
		next;
	    }
	    my @param;

lib/App/Greple/subst/Dict.pm  view on Meta::CPAN

	Text::VisualWidth::PP::width $_[0];
    }

    sub print {
	use List::Util qw(max);
	my $obj = shift;
	my @words = $obj->words;
	my $max = max map { vwidth $_->string  } grep { defined } @words;
	for my $p (@words) {
	    if ($p->is_comment) {
		say $p->comment;
	    } else {
		my($from_re, $to) = ($p->string, $p->correct // '');
		vprintf "%-*s // %s", $max, $from_re // '', $to // '';
		CORE::print "\n";
	    }
	}
    }

    sub to_text {
	my $obj = shift;



( run in 2.577 seconds using v1.01-cache-2.11-cpan-d7a12ab2c7f )