blib/lib/Pod/POM/View.pm

filter: Statementstmt 92.7% 51 / 55 Branchbran 50.0% 16 / 32 Conditioncond 62.5% 5 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 12 / 12 Podpod 100% 7 / 7 totaltotal 78.1% 93 / 119 CC 20 SCAR 17.8
CC
20
Cov
76%
AUTOLOAD
15.0
visiting
6.6
leave
3.1
CRAP 6.0
« blib/lib/Pod/POM/Node.pm ↑ Summary blib/lib/Pod/POM/Node/Sequence.pm »
1 #============================================================= -*-Perl-*-
2 #
3 # Pod::POM::View
4 #
5 # DESCRIPTION
6 # Visitor class for creating a view of all or part of a Pod Object
7 # Model.
8 #
9 # AUTHOR
10 # Andy Wardley <abw@kfs.org>
11 #
12 # COPYRIGHT
13 # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
14 #
15 # This module is free software; you can redistribute it and/or
16 # modify it under the same terms as Perl itself.
17 #
18 # REVISION
19 # $Id: View.pm 32 2009-03-17 21:08:25Z ford $
20 #
21 #========================================================================
22  
23 package Pod::POM::View;
24 18 $Pod::POM::View::VERSION = '2.01';
25 18 require 5.006;
26  
27 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 18 ▶use vars qw( $DEBUG $ERROR $AUTOLOAD $INSTANCE );
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 18 ▶$DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Pod::POM::View::DEBUG 18 0 18
33  
34  
35 #------------------------------------------------------------------------
36 # new($pom)
37 #------------------------------------------------------------------------
38  
39 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
40 1 my $class = shift;
41 1 ▶ my $args = ref $_[0] eq 'HASH' ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 1 1
42 1 bless { %$args }, $class;
43 }
44  
45  
46 10 ▶sub print {
Subroutine print: called CC=2 SCAR=6.9
Pod documented
47 10 my ($self, $item) = @_;
48 10 ▶ return UNIVERSAL::can($item, 'present')
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::can($item, 'present') ? : 9 1 10
49 ? $item->present($self) : $item;
50 }
51
52  
53 7 ▶sub view {
Subroutine view: called CC=1 SCAR=0.0
Pod documented
54 7 my ($self, $type, $node) = @_;
55 7 return $node;
56 }
57  
58  
59 8 ▶sub instance {
Subroutine instance: called CC=3 SCAR=11.1
Pod documented
60 8 my $self = shift;
61 8 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
080
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
62  
63 18 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
64 8 my $instance = \${"$class\::_instance"};
65  
66 8 ▶ defined $$instance
Branch: 1 branch
BranchTrueFalseTotal
defined $$instance ? : 7 1 8
67 ? $$instance
68 : ($$instance = $class->new(@_));
69 }
70  
71  
72 3 ▶sub visit {
Subroutine visit: called CC=3 SCAR=11.0
Pod documented
73 3 my ($self, $place) = @_;
74 3 ▶ $self = $self->instance() unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 3 0 3
75 3 ▶ my $visit = $self->{ VISIT } ||= [ ];
Condition100%2/2
$self->{"VISIT"} ||= []
l!l
21
MC/DC100%1/1
$self->{"VISIT"} ||= []
$self->{"VISIT"}
Truth table100%2/2
A
A= $self->{"VISIT"}
Aresult
11
00
76 3 push(@$visit, $place);
77 3 return $place;
78 }
79  
80  
81 3 ▶sub leave {
Subroutine leave: called CC=3 SCAR=11.3
Pod documented
82 3 my ($self, $place) = @_;
83 3 ▶ $self = $self->instance() unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 3 0 3
84 3 my $visit = $self->{ VISIT };
85 3 ▶ return $self->error('empty VISIT stack') unless @$visit;
Branch: 1 branch
BranchTrueFalseTotal
unless @$visit 0 3 3
86 3 pop(@$visit);
87 }
88  
89  
90 2 ▶sub visiting {
Subroutine visiting: called CC=6 SCAR=18.8
Pod documented
91 2 my ($self, $place) = @_;
92 2 ▶ $self = $self->instance() unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 2 0 2
93 2 my $visit = $self->{ VISIT };
94 2 ▶ return 0 unless $visit && @$visit;
Branch: 1 branch
BranchTrueFalseTotal
unless $visit and @$visit 1 1 2
Condition66%2/3
$visit and @$visit
!ll&&!rl&&r
101
MC/DC50%1/2
$visit and @$visit
$visit @$visit
Truth table66%2/3
A and B
A= $visitB= @$visit
ABresult
0X0
100
111
95  
96 1 foreach (reverse @$visit) {
97 1 ▶ return 1 if $_ eq $place;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $place 1 0 1
98 }
99 0 return 0;
100 }
101
102  
103 594 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=7 SCAR=27.0
104 594 my $self = shift;
105 594 my $name = $AUTOLOAD;
106 594 my $item;
107  
108 594 $name =~ s/.*:://;
109 594 ▶ return if $name eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "DESTROY" 2 592 594
110  
111 592 ▶ if ($name =~ s/^view_//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ s/^view_//) { } 592 0 592
elsif (not ref $self) { } 0 0 0
112 592 return $self->view($name, @_);
113 }
114 elsif (! ref $self) {
115 0 die "can't access $name in $self\n";
116 }
117 else {
118 die "no such method for $self: $name ($AUTOLOAD)"
119 0 ▶ unless defined ($item = $self->{ $name });
Branch: 1 branch
BranchTrueFalseTotal
unless defined($item = $self->{$name}) 0 0 0
120  
121 0 ▶ return wantarray ? ( ref $item eq 'ARRAY' ? @$item : $item ) : $item;
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
ref $item eq 'ARRAY' ? : 0 0 0
122 }
123 }
124  
125  
126 18 1;
127  
128 =head1 NAME
129  
130 Pod::POM::View - view POM objects
131  
132 =head1 DESCRIPTION
133  
134 Visitor class for creating a view of all or part of a Pod Object Model.
135  
136 =head1 METHODS
137  
138 =over 4
139  
140 =item C<new>
141  
142 =item C<print>
143  
144 =item C<view>
145  
146 =item C<instance>
147  
148 =item C<visit>
149  
150 =item C<leave>
151  
152 =item C<visiting>
153  
154 =back
155  
156 =head1 AUTHOR
157  
158 Andy Wardley E<lt>abw@kfs.orgE<gt>
159  
160 =head1 COPYRIGHT AND LICENSE
161  
162 Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
163  
164 This module is free software; you can redistribute it and/or
165 modify it under the same terms as Perl itself.
166  
167 =cut
« blib/lib/Pod/POM/Node.pm ↑ Summary blib/lib/Pod/POM/Node/Sequence.pm »