App-Greple-charcode
view release on metacpan or search on metacpan
lib/App/Greple/annotate.pm view on Meta::CPAN
=head2 PRIVATE MODULE OPTION
Module-specific options are specified between C<-Mannotate> and C<-->.
greple -Mannotate --config alignto=80 -- ...
greple -Mannotate --alignto=80 -- ...
=head2 GENERIC MODULE OPTION
Module-specific C<---config> option can be called by normal command
line option C<--annotate::config>.
greple -Mannotate --annotate::config alignto=80 ...
=head1 INSTALL
cpanm -n B<App::Greple::annotate>
=head1 SEE ALSO
L<App::Greple>
L<App::Greple::charcode>
=head1 LICENSE
Copyrightï¸ Â©ï¸ 2025 Kazumasa Utashiro.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 AUTHOR
Kazumasa Utashiro
=cut
use Getopt::EX::Config;
use Hash::Util qw(lock_keys);
use List::Util qw(max);
use Data::Dumper;
our $config = Getopt::EX::Config->new(
annotate => \(our $opt_annotate = 1),
alignto => 1,
split => 0,
);
lock_keys %{$config};
my %type = ( '*' => ':1' );
sub optspec { $_[0] . ( $type{$_[0]} // $type{'*'} // '' ) }
sub finalize {
our($mod, $argv) = @_;
$config->deal_with($argv,
map(optspec($_), keys %{$config}));
}
use Text::ANSI::Fold::Util qw(ansi_width);
Text::ANSI::Fold->configure(expand => 1);
*vwidth = \&ansi_width;
package # no_index
Local::Annon {
use strict;
use warnings;
sub new {
my $class = shift;
@_ == 3 or die;
bless [ @_ ], $class;
}
sub start { shift->[0] }
sub end { shift->[1] }
sub annon :lvalue { shift->[2] }
}
package # no_index
Local::Annon::List {
use strict;
use warnings;
use List::Util;
sub new {
my $class = shift;
bless {
Annotation => [],
Count => [],
}, $class;
}
sub annotation { $_[0]->{Annotation} }
sub count { $_[0]->{Count} }
sub push {
my $obj = CORE::shift;
push @{$obj->annotation}, @_;
push @{$obj->count}, int @_;
}
sub append {
my $obj = CORE::shift;
CORE::push @{$obj->annotation}, @_;
$obj->count->[-1] += int @_;
}
sub shift {
my $obj = CORE::shift;
my $count = CORE::shift @{$obj->count} or return ();
splice @{$obj->annotation}, 0, $count;
}
sub join {
my $obj = CORE::shift;
for (@_) {
CORE::push @{$obj->annotation}, @{$_->annotation};
CORE::push @{$obj->count}, @{$_->count};
}
}
sub total {
my $obj = CORE::shift;
List::Util::sum(@{$obj->count}) // 0;
}
sub last {
my $obj = CORE::shift;
$obj->annotation->[-1];
}
( run in 0.591 second using v1.01-cache-2.11-cpan-5623c5533a1 )