File Coverage

blib/lib/Dotiac/DTL/Tag/ifequal.pm
Criterion Covered Total %
statement 85 92 92.3
branch 20 22 90.9
condition n/a
subroutine 12 14 85.7
pod 11 11 100.0
total 128 139 92.0


line stmt bran cond sub pod time code
1             #ifequal.pm
2             #Last Change: 2009-01-19
3             #Copyright (c) 2009 Marc-Seabstian "Maluku" Lucksch
4             #Version 0.8
5             ####################
6             #This file is part of the Dotiac::DTL project.
7             #http://search.cpan.org/perldoc?Dotiac::DTL
8             #
9             #ifequal.pm is published under the terms of the MIT license, which basically
10             #means "Do with it whatever you want". For more information, see the
11             #license.txt file that should be enclosed with libsofu distributions. A copy of
12             #the license is (at the time of writing) also available at
13             #http://www.opensource.org/licenses/mit-license.php .
14             ###############################################################################
15            
16             package Dotiac::DTL::Tag::ifequal;
17 11     11   59 use base qw/Dotiac::DTL::Tag/;
  11         26  
  11         935  
18 11     11   65 use strict;
  11         22  
  11         346  
19 11     11   56 use warnings;
  11         21  
  11         14753  
20            
21             our $VERSION = 0.8;
22            
23             sub new {
24 11     11 1 22 my $class=shift;
25 11         35 my $self={p=>shift()};
26 11         23 my $name=shift;
27 11         16 my $obj=shift;
28 11         16 my $data=shift;
29 11         15 my $pos=shift;
30 11         17 my $found="";
31 11         45 $self->{true}=$obj->parse($data,$pos,\$found,"else","endifequal");
32 11 100       32 if ($found eq "else") {
33 6         21 $self->{false}=$obj->parse($data,$pos,\$found,"endifequal");
34             }
35 11         35 ($self->{var1},$self->{var2},undef)=Dotiac::DTL::get_variables($name);
36 11         34 bless $self,$class;
37 11         38 return $self;
38             }
39             sub print {
40 29     29 1 44 my $self=shift;
41 29         49 print $self->{p};
42 29         179 my $r=Dotiac::DTL::devar_raw($self->{var1},@_)->true();
43 29         119 my $v=Dotiac::DTL::devar_raw($self->{var2},@_)->true();
44 29 100       97 if ($r eq $v) {
45 7         30 $self->{true}->print(@_);
46             }
47             else {
48 22 100       94 $self->{false}->print(@_) if $self->{false};
49             }
50 29         103 $self->{n}->print(@_);
51             }
52             sub string {
53 29     29 1 43 my $self=shift;
54 29         80 my $r=Dotiac::DTL::devar_raw($self->{var1},@_)->true();
55 29         115 my $v=Dotiac::DTL::devar_raw($self->{var2},@_)->true();
56 29 100       104 if ($r eq $v) {
57 7         32 return $self->{p}.$self->{true}->string(@_).$self->{n}->string(@_);
58             }
59 22 100       103 return $self->{p}.($self->{false}?$self->{false}->string(@_):"").$self->{n}->string(@_);
60            
61             }
62             sub perl {
63 11     11 1 16 my $self=shift;
64 11         16 my $fh=shift;
65 11         18 my $id=shift;
66 11         47 $self->SUPER::perl($fh,$id,@_);
67 11         23 print $fh "my ";
68 11         65 print $fh (Data::Dumper->Dump([$self->{var1}],["\$vara$id"]));
69 11         554 print $fh "my ";
70 11         134 print $fh (Data::Dumper->Dump([$self->{"var2"}],["\$varb$id"]));
71 11         449 $id = $self->{true}->perl($fh,$id+1,@_);
72 11 100       55 $id = $self->{false}->perl($fh,$id+1,@_) if $self->{false};
73 11         60 return $self->{n}->perl($fh,$id+1,@_)
74             }
75             sub perlinit {
76 11     11 1 16 my $self=shift;
77 11         13 my $fh=shift;
78 11         17 my $id=shift;
79 11         41 $id = $self->{true}->perlinit($fh,$id+1,@_);
80 11 100       46 $id = $self->{false}->perlinit($fh,$id+1,@_) if $self->{false};
81 11         83 return $self->{n}->perlinit($fh,$id+1,@_)
82             }
83             sub perlprint {
84 11     11 1 19 my $self=shift;
85 11         16 my $fh=shift;
86 11         15 my $id=shift;
87 11         14 my $level=shift;
88 11         42 $self->SUPER::perlprint($fh,$id,$level,@_);
89 11         60 print $fh "\t" x $level,"if (Dotiac::DTL::devar_raw(\$vara$id,\$vars,\$escape.\@_)->true() eq Dotiac::DTL::devar_raw(\$varb$id,\$vars,\$escape.\@_)->true()) {\n";
90 11         46 $id = $self->{true}->perlprint($fh,$id+1,$level+1,@_);
91 11 100       34 if ($self->{false}) {
92 6         17 print $fh "\t" x $level,"} else {\n";
93 6         26 $id = $self->{false}->perlprint($fh,$id+1,$level+1,@_);
94             }
95 11         27 print $fh "\t" x $level,"}\n";
96 11         60 return $self->{n}->perlprint($fh,$id+1,$level,@_);
97             }
98             sub perlstring {
99 11     11 1 17 my $self=shift;
100 11         15 my $fh=shift;
101 11         14 my $id=shift;
102 11         13 my $level=shift;
103 11         60 $self->SUPER::perlstring($fh,$id,$level,@_);
104 11         45 print $fh "\t" x $level,"if (Dotiac::DTL::devar_raw(\$vara$id,\$vars,\$escape.\@_)->true() eq Dotiac::DTL::devar_raw(\$varb$id,\$vars,\$escape.\@_)->true()) {\n";
105 11         61 $id = $self->{true}->perlstring($fh,$id+1,$level+1,@_);
106 11 100       34 if ($self->{false}) {
107 6         26 print $fh "\t" x $level,"} else {\n";
108 6         28 $id = $self->{false}->perlstring($fh,$id+1,$level+1,@_);
109             }
110 11         28 print $fh "\t" x $level,"}\n";
111 11         70 return $self->{n}->perlstring($fh,$id+1,$level,@_);
112             }
113             sub perleval {
114 11     11 1 24 my $self=shift;
115 11         14 my $fh=shift;
116 11         18 my $id=shift;
117 11         43 $id=$self->{true}->perleval($fh,$id+1,@_);
118 11 100       45 $id=$self->{false}->perleval($fh,$id+1,@_) if $self->{false};
119 11         61 $self->{n}->perleval($fh,$id+1,@_);
120             }
121             sub perlcount {
122 0     0 1 0 my $self=shift;
123 0         0 my $id=shift;
124 0         0 $id=$self->{true}->perlcount($id+1,@_);
125 0 0       0 $id=$self->{false}->perlcount($id+1,@_) if $self->{false};
126 0         0 return $self->{n}->perlcount($id+1);
127             }
128             sub next {
129 11     11 1 15 my $self=shift;
130 11         45 $self->{n}=shift;
131             }
132             sub eval {
133 0     0 1   my $self=shift;
134 0           $self->{n}->eval(@_);
135             }
136             1;
137            
138             __END__