Ancient
view release on metacpan or search on metacpan
lib/file.pm view on Meta::CPAN
=head1 LINE PROCESSING
Advanced line processing functions for filtering and transforming file content.
=head2 count_lines
my $count = file::count_lines($path);
my $count = file::count_lines($path, $predicate);
Count lines in a file. With a predicate, counts only matching lines.
my $total = file::count_lines($path);
my $non_blank = file::count_lines($path, 'is_not_blank');
my $long = file::count_lines($path, sub { length(shift) > 80 });
=head2 find_line
my $line = file::find_line($path, $predicate);
Find and return the first line matching a predicate. Returns undef if
no match found.
my $comment = file::find_line($path, 'is_comment');
my $error = file::find_line($path, sub { /ERROR/ });
=head2 grep_lines
my $lines = file::grep_lines($path, $predicate);
Filter lines matching a predicate. Returns arrayref.
my $comments = file::grep_lines($path, 'is_comment');
my $non_blank = file::grep_lines($path, 'is_not_blank');
my $errors = file::grep_lines($path, sub { /ERROR|WARN/ });
=head2 map_lines
my $result = file::map_lines($path, $transform);
Transform each line. Returns arrayref of transformed values.
my $upper = file::map_lines($path, sub { uc(shift) });
my $lengths = file::map_lines($path, sub { length($_) });
=head1 LINE CALLBACKS
Register custom predicates for use with grep_lines, count_lines, etc.
=head2 register_line_callback
file::register_line_callback($name, $coderef);
Register a named predicate for line filtering.
file::register_line_callback('is_todo', sub { /TODO|FIXME/ });
# Now use it:
my $todos = file::grep_lines($path, 'is_todo');
=head2 list_line_callbacks
my $names = file::list_line_callbacks();
Returns arrayref of all registered callback names.
Built-in predicates: C<is_blank>, C<is_not_blank>, C<blank>, C<not_blank>,
C<is_empty>, C<is_not_empty>, C<is_comment>, C<is_not_comment>.
=head1 AUTHOR
LNATION
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
( run in 0.505 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )