| 1 | package App::Ack::Files; | ||||||||||
| 2 | |||||||||||
| 3 | 580 | ▶ | use App::Ack (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 580 | ▶ | use App::Ack::File (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 580 | ▶ | use File::Next 1.16 (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 580 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 580 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 580 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | =head1 NAME | ||||||||||
| 13 | |||||||||||
| 14 | App::Ack::Files | ||||||||||
| 15 | |||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||
| 17 | |||||||||||
| 18 | A factory object for creating a stream of L<App::Ack::File> objects. | ||||||||||
| 19 | |||||||||||
| 20 | =head1 METHODS | ||||||||||
| 21 | |||||||||||
| 22 | =head2 from_argv( \%opt, \@starting_points ) | ||||||||||
| 23 | |||||||||||
| 24 | Return an iterator that does the file finding for us. | ||||||||||
| 25 | |||||||||||
| 26 | =cut | ||||||||||
| 27 | |||||||||||
| 28 | 317 | ▶ | sub from_argv { | ||||||||
|
Subroutine
from_argv: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 29 | 317 | my $class = shift; | |||||||||
| 30 | 317 | my $opt = shift; | |||||||||
| 31 | 317 | my $start = shift; | |||||||||
| 32 | |||||||||||
| 33 | 317 | my $self = bless {}, $class; | |||||||||
| 34 | |||||||||||
| 35 | 317 | my $descend_filter = $opt->{descend_filter}; | |||||||||
| 36 | |||||||||||
| 37 | 317 | ▶ | if ( $opt->{n} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 10 | ▶ | $descend_filter = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 39 | 10 | return 0; | |||||||||
| 40 | 2 | }; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | $self->{iter} = | ||||||||||
| 44 | File::Next::files( { | ||||||||||
| 45 | file_filter => $opt->{file_filter}, | ||||||||||
| 46 | descend_filter => $descend_filter, | ||||||||||
| 47 | error_handler => _generate_error_handler(), | ||||||||||
| 48 | 0 | ▶ | warning_handler => sub {}, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||
| 49 | sort_files => $opt->{sort_files}, | ||||||||||
| 50 | follow_symlinks => $opt->{follow}, | ||||||||||
| 51 | 317 | }, @{$start} ); | |||||||||
| 52 | |||||||||||
| 53 | 317 | return $self; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | =head2 from_file( \%opt, $filename ) | ||||||||||
| 57 | |||||||||||
| 58 | Return an iterator that reads the list of files to search from a | ||||||||||
| 59 | given file. If I<$filename> is '-', then it reads from STDIN. | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||
| 62 | |||||||||||
| 63 | 9 | ▶ | sub from_file { | ||||||||
|
Subroutine
from_file: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 64 | 9 | my $class = shift; | |||||||||
| 65 | 9 | my $opt = shift; | |||||||||
| 66 | 9 | my $file = shift; | |||||||||
| 67 | |||||||||||
| 68 | 9 | my $error_handler = _generate_error_handler(); | |||||||||
| 69 | my $iter = | ||||||||||
| 70 | File::Next::from_file( { | ||||||||||
| 71 | error_handler => $error_handler, | ||||||||||
| 72 | warning_handler => $error_handler, | ||||||||||
| 73 | sort_files => $opt->{sort_files}, | ||||||||||
| 74 | 9 | ▶ | }, $file ) or return undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | |||||||||||
| 76 | 8 | return bless { | |||||||||
| 77 | iter => $iter, | ||||||||||
| 78 | }, $class; | ||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | |||||||||||
| 82 | =head2 from_stdin() | ||||||||||
| 83 | |||||||||||
| 84 | This is for reading input lines from STDIN, not the list of files | ||||||||||
| 85 | from STDIN. | ||||||||||
| 86 | |||||||||||
| 87 | =cut | ||||||||||
| 88 | |||||||||||
| 89 | |||||||||||
| 90 | 6 | ▶ | sub from_stdin { | ||||||||
|
Subroutine
from_stdin: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 91 | 6 | my $class = shift; | |||||||||
| 92 | |||||||||||
| 93 | 6 | my $self = bless {}, $class; | |||||||||
| 94 | |||||||||||
| 95 | 10 | ▶ | $self->{iter} = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 96 | 10 | state $has_been_called = 0; | |||||||||
| 97 | |||||||||||
| 98 | 10 | ▶ | if ( !$has_been_called ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | 5 | $has_been_called = 1; | |||||||||
| 100 | 5 | return '-'; | |||||||||
| 101 | } | ||||||||||
| 102 | 5 | return; | |||||||||
| 103 | 6 | }; | |||||||||
| 104 | |||||||||||
| 105 | 6 | return $self; | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | |||||||||||
| 109 | 3954 | ▶ | sub next { | ||||||||
|
Subroutine
next: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 110 | 3954 | my $self = shift; | |||||||||
| 111 | |||||||||||
| 112 | 3954 | my $file = $self->{iter}->(); | |||||||||
| 113 | |||||||||||
| 114 | 3954 | ▶ | return unless defined($file); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | |||||||||||
| 116 | 3624 | return App::Ack::File->new( $file ); | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | |||||||||||
| 120 | 326 | ▶ | sub _generate_error_handler { | ||||||||
|
Subroutine
_generate_error_handler: called CC=2 SCAR=6.9
| |||||||||||
| 121 | 326 | ▶ | if ( $App::Ack::report_bad_filenames ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | 3 | ▶ | return sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 123 | 3 | my $msg = shift; | |||||||||
| 124 | 3 | App::Ack::warn( $msg ); | |||||||||
| 125 | 324 | }; | |||||||||
| 126 | } | ||||||||||
| 127 | else { | ||||||||||
| 128 | 2 | ▶ | return sub {}; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 129 | } | ||||||||||
| 130 | } | ||||||||||
| 131 | |||||||||||
| 132 | 580 | 1; | |||||||||