blib/lib/PMLTQ/Relation/FSFileIterator.pm

filter: Statementstmt 47.7% 43 / 90 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 56.5% 13 / 23 Podpod 0.0% 0 / 9 totaltotal 32.1% 56 / 174 CC 20 SCAR 31.1
CC
20
Cov
33%
next
72.0
start
30.0
set_file
20.0
CRAP 22.5
« blib/lib/PMLTQ/Relation/Treex/TEParentIterator.pm ↑ Summary blib/lib/PMLTQ/Relation/SiblingIterator.pm »
1 package PMLTQ::Relation::FSFileIterator;
2 12 our $AUTHORITY = 'cpan:MATY';
3 12 $PMLTQ::Relation::FSFileIterator::VERSION = '1.5.0';
4 # ABSTRACT: Iterates nodes of given fsfile
5  
6 12 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use base qw(PMLTQ::Relation::Iterator);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use constant CONDITIONS=>0;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 ▶use constant FILE=>1;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 12 ▶use constant TREE_NO=>2;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 12 ▶use constant TREES=>3;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 12 ▶use constant NODE=>4;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 12 ▶use constant TREEX_DOC=>5;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 12 ▶use PMLTQ::Loader 'load_class';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 12 ▶use English qw(-no_match_vars); # Load this because otherwise Treex::Core ends up with error on Perl 5.14
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 12 our $PROGRESS; ### newly added
23 12 our $STOP; ### newly added
24  
25 sub new {
26 0 ▶ my ($class,$conditions,$fsfile)=@_;
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
27 0 ▶ croak "usage: $class->new(sub{...})" unless ref($conditions) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $conditions eq "CODE" 0 0 0
28 0 my $obj = bless [$conditions],$class;
29 0 ▶ $obj->set_file($fsfile) if $fsfile;
Branch: 1 branch
BranchTrueFalseTotal
if $fsfile 0 0 0
30 0 return $obj;
31 }
32 sub clone {
33 0 ▶ my ($self)=@_;
Subroutine clone: not called CC=1 SCAR=6.9
Pod undocumented
34 0 return bless [$self->[CONDITIONS],$self->[FILE]], ref($self);
35 }
36 sub tree {
37 0 ▶ my ($self, $n)=@_;
Subroutine tree: not called CC=1 SCAR=6.9
Pod undocumented
38 0 return $self->[TREES]->[$n];
39 }
40 sub start {
41 0 ▶ my ($self,undef,$fsfile)=@_;
Subroutine start: not called CC=5 SCAR=34.0
Pod undocumented
42 0 $self->[TREE_NO]=0;
43 0 ▶ if ($fsfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fsfile) { } 0 0 0
44 0 $self->set_file($fsfile);
45 } else {
46 0 $fsfile=$self->[FILE];
47 }
48 0 my $n = $self->[NODE] = $self->tree(0);
49 0 ▶ return ($n && $self->[CONDITIONS]->($n,$fsfile)) ? $n : ($n && $self->next);
Branch: 1 branch
BranchTrueFalseTotal
$n && $self->[0]->($n, $fsfile) ? : 0 0 0
Condition0%0/6
$n and $self->[0]->($n, $fsfile)
!ll&&!rl&&r
000
$n and $self->next
!ll&&!rl&&r
000
MC/DC0%0/2
$n and $self->[0]->($n, $fsfile)
$n $self->[0]->($n, $fsfile)
MC/DC0%0/2
$n and $self->next
$n $self->next
Truth table0%0/3
A and B
A= $nB= $self->[0]->($n, $fsfile)
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $nB= $self->next
ABresult
0X0
100
111
50 }
51 sub next {
52 0 ▶ my ($self)=@_;
Subroutine next: not called CC=8 SCAR=42.8
Pod undocumented
53 0 my $conditions=$self->[CONDITIONS];
54 0 my $n=$self->[NODE];
55 0 my $fsfile=$self->[FILE];
56 0 ▶ while ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 0 0
57 # Treex has following hacked but we want to have classic following
58 0 ▶ $n = Treex::PML::Node::following($n) || (($PROGRESS ? $PROGRESS->() : 1) && $STOP && do { $n = undef; last }) || $self->tree(++$self->[TREE_NO]);
Branch: 1 branch
BranchTrueFalseTotal
$PMLTQ::Relation::FSFileIterator::PROGRESS ? : 0 0 0
Condition0%0/12
Treex::PML::Node::following($n) || ($PMLTQ::Relation::FSFileIterator::PROGRESS ? &$PMLTQ::Relation::FSFileIterator::PROGRESS() : 1) && $PMLTQ::Relation::FSFileIterator::STOP && do { $n = undef; last } || $self->tree(++$self->[2])
l!l&&r!l&&!r
000
Treex::PML::Node::following($n) or $PMLTQ::Relation::FSFileIterator::PROGRESS ? &$PMLTQ::Relation::FSFileIterator::PROGRESS() : 1 and $PMLTQ::Relation::FSFileIterator::STOP and do { $n = undef; last }
l!l&&r!l&&!r
000
$PMLTQ::Relation::FSFileIterator::PROGRESS ? &$PMLTQ::Relation::FSFileIterator::PROGRESS() : 1 and $PMLTQ::Relation::FSFileIterator::STOP and do { $n = undef; last }
!ll&&!rl&&r
000
$PMLTQ::Relation::FSFileIterator::PROGRESS ? &$PMLTQ::Relation::FSFileIterator::PROGRESS() : 1 and $PMLTQ::Relation::FSFileIterator::STOP
!ll&&!rl&&r
000
MC/DC0%0/5
Treex::PML::Node::following($n) || ($PMLTQ::Relation::FSFileIterator::PROGRESS ? &$PMLTQ::Relation::FSFileIterator::PROGRESS() : 1) && $PMLTQ::Relation::FSFileIterator::STOP && do { $n = undef; last } || $self->tree(++$self->[2])
Treex::PML::Node::following($n) $PMLTQ::Relation::FSFileIterator::PROGRESS ? &$PMLTQ::Relation::FSFileIterator::PROGRESS() : 1 $PMLTQ::Relation::FSFileIterator::STOP do { $n = undef; last } $self->tree(++$self->[2])
Truth table0%0/8
A or B and C and D || E
A= Treex::PML::Node::following($n)B= $PMLTQ::Relation::FSFileIterator::PROGRESS ? &$PMLTQ::Relation::FSFileIterator::PROGRESS() : 1C= $PMLTQ::Relation::FSFileIterator::STOPD= do { $n = undef; last }E= $self->tree(++$self->[2])
ABCDEresult
1XXXX1
0111X1
00XX11
010X11
011011
00XX00
010X00
011000
59 0 ▶ last if $conditions->($n,$fsfile);
Branch: 1 branch
BranchTrueFalseTotal
if &$conditions($n, $fsfile) 0 0 0
60 }
61 0 return $self->[NODE]=$n;
62 }
63 sub node {
64 0 ▶ return $_[0]->[NODE];
Subroutine node: not called CC=1 SCAR=6.9
Pod undocumented
65 }
66 sub file {
67 0 ▶ return $_[0]->[FILE];
Subroutine file: not called CC=1 SCAR=6.9
Pod undocumented
68 }
69 sub set_file {
70 0 ▶ my ($self, $file) = @_;
Subroutine set_file: not called CC=4 SCAR=30.0
Pod undocumented
71 0 $self->[FILE] = $file;
72 0 my $schema_name = $file->schema->get_root_name;
73  
74 0 ▶ if ($schema_name && $schema_name eq 'treex_document') {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema_name and $schema_name eq 'treex_document') { } 0 0 0
Condition0%0/3
$schema_name and $schema_name eq "treex_document"
!ll&&!rl&&r
000
MC/DC0%0/2
$schema_name and $schema_name eq "treex_document"
$schema_name $schema_name eq "treex_document"
Truth table0%0/3
A and B
A= $schema_nameB= $schema_name eq "treex_document"
ABresult
0X0
100
111
75 0 ▶ croak 'Please install Treex::Core if you want to use PML-TQ with treex files' unless load_class('Treex::Core::Document');
Branch: 1 branch
BranchTrueFalseTotal
unless load_class("Treex::Core::Document") 0 0 0
76 0 $self->[TREEX_DOC] = Treex::Core::Document->new({pmldoc => $file}); # Will convert the file to Treex Document in place
77 0 $self->_extract_trees;
78 } else {
79 0 $self->[TREES] = [$file->trees];
80 }
81 0 return $file;
82 }
83 sub reset {
84 0 ▶ my ($self)=@_;
Subroutine reset: not called CC=1 SCAR=6.9
Pod undocumented
85 0 $self->[NODE]=undef;
86 }
87  
88 sub _extract_trees {
89 0 ▶ my ($self)=@_;
Subroutine _extract_trees: not called CC=4 SCAR=30.0
90 0 my $doc = $self->[TREEX_DOC];
91 # lets assume it's a treex doc
92 0 $self->[TREES] = [];
93 0 foreach my $bundle ($doc->get_bundles) {
94 0 ▶ last unless defined $bundle->{zones};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bundle->{"zones"} 0 0 0
95 0 foreach my $zone ($bundle->get_all_zones) {
96 0 push @{$self->[TREES]}, $zone->get_all_trees;
97 }
98 }
99 }
100  
101 12 1; # End of PMLTQ::Relation::FSFileIterator
102  
103 __END__
« blib/lib/PMLTQ/Relation/Treex/TEParentIterator.pm ↑ Summary blib/lib/PMLTQ/Relation/SiblingIterator.pm »