| 1 | package Perl::Analysis::Static::Questioner; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 3 | $Perl::Analysis::Static::Questioner::VERSION = '0.004'; # TRIAL | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: ask a question about a Perl document | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use English qw( -no_match_vars ); # Avoids regex performance penalty | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Module::Runtime qw(use_module); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Perl::Analysis::Static::Document; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Perl::Analysis::Static::Answer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use Perl::Analysis::Static::Collector; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | sub ask_for_file { | ||||||||||||||||||||||||||
|
Subroutine
ask_for_file: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 3 | my ( $self, $question, $filename ) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | my $document = | |||||||||||||||||||||||||||
| 24 | Perl::Analysis::Static::Document->new( filename => $filename ); | ||||||||||||||||||||||||||||
| 25 | 3 | ▶ | unless ($document) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | App::Perlanalyst::die( | |||||||||||||||||||||||||||
| 27 | "Unable to get document instance for file '$filename'"); | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 3 | return $self->ask_for_document( $question, $document ); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 3 | ▶ | sub ask_for_document { | ||||||||||||||||||||||||||
|
Subroutine
ask_for_document: called CC=5 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 3 | my ( $self, $question, $document ) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 3 | ▶ | unless ($document) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | App::Perlanalyst::die('Argument error: need document'); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # find all elements of this class | ||||||||||||||||||||||||||||
| 42 | 3 | my $elements = $document->find( $question->class() ); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # return if we didn't find anything | ||||||||||||||||||||||||||||
| 45 | 3 | ▶ | return unless $elements; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # filter the elements if we have to | ||||||||||||||||||||||||||||
| 48 | 3 | ▶ | $elements = $self->_filter( $question, $elements ) if $question->{filter}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # return immediately if we filtered everything | ||||||||||||||||||||||||||||
| 51 | 3 | ▶ | return unless $elements; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 3 | my $answer = Perl::Analysis::Static::Answer->new( elements => $elements ); | |||||||||||||||||||||||||||
| 54 | 3 | return $answer; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub ask_for_files { | ||||||||||||||||||||||||||
|
Subroutine
ask_for_files: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 0 | my ( $self, $question, $files, $step_hook ) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | my $collector = Perl::Analysis::Static::Collector->new(); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | for my $file (@$files) { | |||||||||||||||||||||||||||
| 64 | 0 | my $answer = | |||||||||||||||||||||||||||
| 65 | $self->ask_for_file( $question, $file ); | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $collector->set_answer( $file, $answer ) if $answer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | &$step_hook($file) if $step_hook and ref $step_hook eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$step_hook and ref $step_hook eq "CODE"
MC/DC0%0/2
$step_hook and ref $step_hook eq "CODE"
$step_hook
ref $step_hook eq "CODE"
Truth table0%0/3
A and B
A= $step_hookB= ref $step_hook eq "CODE"
| |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | return $collector; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 3 | ▶ | sub _filter { | ||||||||||||||||||||||||||
|
Subroutine
_filter: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 75 | 3 | my ( $self, $question, $elements ) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 3 | my @filters = @{ $question->filter }; | |||||||||||||||||||||||||||
| 78 | 3 | my @arguments = @{ $question->arguments }; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | for my $filter_class (@filters) { | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # preprend Perl::Analysis::Static::Filter if it's not already there | ||||||||||||||||||||||||||||
| 83 | 3 | ▶ | unless ( $filter_class =~ m{^Perl::Analysis::Static::Filter::} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 3 | $filter_class = 'Perl::Analysis::Static::Filter::' . $filter_class; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # load the filter's module | ||||||||||||||||||||||||||||
| 88 | 3 | use_module($filter_class); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # create instance and set its arguments | ||||||||||||||||||||||||||||
| 91 | 3 | my $filter = $filter_class->new(); | |||||||||||||||||||||||||||
| 92 | 3 | my $arguments = shift @arguments; | |||||||||||||||||||||||||||
| 93 | 3 | $filter->set_arguments($arguments); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # filter the elements | ||||||||||||||||||||||||||||
| 96 | 3 | $elements = $filter->filter($elements); | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 3 | return $elements; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 3 | 1; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||