File Coverage

blib/lib/Plosurin/AbstractVisiter.pm
Criterion Covered Total %
statement 33 41 80.4
branch 7 12 58.3
condition 7 12 58.3
subroutine 7 8 87.5
pod 0 3 0.0
total 54 76 71.0


line stmt bran cond sub pod time code
1             #===============================================================================
2             #
3             # DESCRIPTION: Abstract Class for Nodes Visiter
4             #
5             # AUTHOR: Aliaksandr P. Zahatski, <zahatski@gmail.com>
6             #===============================================================================
7             package Plosurin::AbstractVisiter;
8 4     4   30 use strict;
  4         11  
  4         121  
9 4     4   21 use warnings;
  4         10  
  4         110  
10 4     4   23 use vars qw($AUTOLOAD);
  4         9  
  4         1958  
11             our $VERSION = '0.01';
12              
13              
14             sub new {
15 39     39 0 136 my $class = shift;
16 39 50 33     252 my $self = bless( $#_ == 0 ? shift : {@_}, ref($class) || $class );
17 39         101 $self;
18             }
19              
20             sub visit {
21 138     138 0 210 my $self = shift;
22 138         185 my $n = shift;
23              
24             #get type of file
25 138         224 my $ref = ref($n);
26 138 50 66     715 unless ( ref($n) && UNIVERSAL::isa( $n, 'Soy::base' )
      66        
      66        
27             || UNIVERSAL::isa( $n, 'Plo::File' )
28             || UNIVERSAL::isa( $n, 'Plo::template' ) )
29             {
30 34 50       82 if ( ref($n) eq 'ARRAY' ) {
31 34         134 $self->visit($_) for @$n;
32             }
33             else {
34 0         0 die "Unknown node type $n (not isa Soy::base)";
35             }
36             }
37              
38 138         233 my $method = ref($n);
39 138         482 $method =~ s/.*:://;
40              
41             #make method name
42 138         650 $self->$method($n);
43             }
44              
45             sub visit_childs {
46 60     60 0 96 my $self = shift;
47 60         116 foreach my $n (@_) {
48 60 50       227 die "Unknow type $n (not isa Soy::base)"
49             unless UNIVERSAL::isa( $n, 'Soy::base' );
50 60         86 foreach my $ch ( @{ $n->childs } ) {
  60         152  
51 61         132 $self->visit($ch);
52             }
53             }
54             }
55              
56             sub __default_method {
57 0     0   0 my $self =shift;
58 0         0 my $n = shift;
59 0         0 my $method = ref($n);
60 0         0 $method =~ s/.*:://;
61 0         0 die ref($self) . ": Method '$method' for class " . ref($n) . " not implemented at ";
62             }
63              
64             sub AUTOLOAD {
65 124     124   30225 my $self = shift;
66 124         198 my $method = $AUTOLOAD;
67 124         454 $method =~ s/.*:://;
68 124 100       643 return if $method eq 'DESTROY';
69              
70             #check if can
71 82 50       246 if ( $self->can($method) ) {
72 0         0 my $superior = "SUPER::$method";
73 0         0 $self->$superior(@_);
74             }
75             else {
76 82         205 $self->__default_method(@_);
77             }
78             }
79              
80             1;
81