File Coverage

blib/lib/Dotiac/DTL/Tag/ifnotequal.pm
Criterion Covered Total %
statement 85 92 92.3
branch 18 22 81.8
condition n/a
subroutine 12 14 85.7
pod 11 11 100.0
total 126 139 90.6


line stmt bran cond sub pod time code
1             #ifnotequal.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             #ifnotequal.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::ifnotequal;
17 11     11   58 use base qw/Dotiac::DTL::Tag/;
  11         32  
  11         867  
18 11     11   58 use strict;
  11         23  
  11         323  
19 11     11   65 use warnings;
  11         46  
  11         16467  
20            
21             our $VERSION = 0.8;
22            
23             sub new {
24 9     9 1 15 my $class=shift;
25 9         23 my $self={p=>shift()};
26 9         15 my $name=shift;
27 9         13 my $obj=shift;
28 9         13 my $data=shift;
29 9         11 my $pos=shift;
30 9         10 my $found="";
31 9         38 $self->{true}=$obj->parse($data,$pos,\$found,"else","endifnotequal");
32 9 100       25 if ($found eq "else") {
33 5         16 $self->{false}=$obj->parse($data,$pos,\$found,"endifnotequal");
34             }
35 9         28 ($self->{var1},$self->{var2},undef)=Dotiac::DTL::get_variables($name);
36 9         28 bless $self,$class;
37 9         30 return $self;
38             }
39             sub print {
40 9     9 1 13 my $self=shift;
41 9         15 print $self->{p};
42 9         25 my $r=Dotiac::DTL::devar_raw($self->{var1},@_)->true();
43 9         34 my $v=Dotiac::DTL::devar_raw($self->{var2},@_)->true();
44 9 100       32 if ($r ne $v) {
45 5         22 $self->{true}->print(@_);
46             }
47             else {
48 4 50       20 $self->{false}->print(@_) if $self->{false};
49             }
50 9         45 $self->{n}->print(@_);
51             }
52             sub string {
53 9     9 1 14 my $self=shift;
54 9         31 my $r=Dotiac::DTL::devar_raw($self->{var1},@_)->true();
55 9         37 my $v=Dotiac::DTL::devar_raw($self->{var2},@_)->true();
56 9 100       35 if ($r ne $v) {
57 5         22 return $self->{p}.$self->{true}->string(@_).$self->{n}->string(@_);
58             }
59 4 50       23 return $self->{p}.($self->{false}?$self->{false}->string(@_):"").$self->{n}->string(@_);
60            
61             }
62             sub perl {
63 9     9 1 16 my $self=shift;
64 9         12 my $fh=shift;
65 9         13 my $id=shift;
66 9         36 $self->SUPER::perl($fh,$id,@_);
67 9         18 print $fh "my ";
68 9         50 print $fh (Data::Dumper->Dump([$self->{var1}],["\$vara$id"]));
69 9         362 print $fh "my ";
70 9         47 print $fh (Data::Dumper->Dump([$self->{"var2"}],["\$varb$id"]));
71 9         379 $id = $self->{true}->perl($fh,$id+1,@_);
72 9 100       43 $id = $self->{false}->perl($fh,$id+1,@_) if $self->{false};
73 9         49 return $self->{n}->perl($fh,$id+1,@_)
74             }
75             sub perlinit {
76 9     9 1 14 my $self=shift;
77 9         11 my $fh=shift;
78 9         12 my $id=shift;
79 9         29 $id = $self->{true}->perlinit($fh,$id+1,@_);
80 9 100       36 $id = $self->{false}->perlinit($fh,$id+1,@_) if $self->{false};
81 9         33 return $self->{n}->perlinit($fh,$id+1,@_)
82             }
83             sub perlprint {
84 9     9 1 12 my $self=shift;
85 9         11 my $fh=shift;
86 9         9 my $id=shift;
87 9         9 my $level=shift;
88 9         31 $self->SUPER::perlprint($fh,$id,$level,@_);
89 9         36 print $fh "\t" x $level,"if (Dotiac::DTL::devar_raw(\$vara$id,\$vars,\$escape.\@_)->true() ne Dotiac::DTL::devar_raw(\$varb$id,\$vars,\$escape.\@_)->true()) {\n";
90 9         33 $id = $self->{true}->perlprint($fh,$id+1,$level+1,@_);
91 9 100       28 if ($self->{false}) {
92 5         9 print $fh "\t" x $level,"} else {\n";
93 5         19 $id = $self->{false}->perlprint($fh,$id+1,$level+1,@_);
94             }
95 9         19 print $fh "\t" x $level,"}\n";
96 9         63 return $self->{n}->perlprint($fh,$id+1,$level,@_);
97             }
98             sub perlstring {
99 9     9 1 18 my $self=shift;
100 9         10 my $fh=shift;
101 9         12 my $id=shift;
102 9         11 my $level=shift;
103 9         34 $self->SUPER::perlstring($fh,$id,$level,@_);
104 9         33 print $fh "\t" x $level,"if (Dotiac::DTL::devar_raw(\$vara$id,\$vars,\$escape.\@_)->true() ne Dotiac::DTL::devar_raw(\$varb$id,\$vars,\$escape.\@_)->true()) {\n";
105 9         88 $id = $self->{true}->perlstring($fh,$id+1,$level+1,@_);
106 9 100       27 if ($self->{false}) {
107 5         12 print $fh "\t" x $level,"} else {\n";
108 5         18 $id = $self->{false}->perlstring($fh,$id+1,$level+1,@_);
109             }
110 9         25 print $fh "\t" x $level,"}\n";
111 9         51 return $self->{n}->perlstring($fh,$id+1,$level,@_);
112             }
113             sub perleval {
114 9     9 1 11 my $self=shift;
115 9         12 my $fh=shift;
116 9         7 my $id=shift;
117 9         31 $id=$self->{true}->perleval($fh,$id+1,@_);
118 9 100       33 $id=$self->{false}->perleval($fh,$id+1,@_) if $self->{false};
119 9         36 $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 9     9 1 13 my $self=shift;
130 9         39 $self->{n}=shift;
131             }
132             sub eval {
133 0     0 1   my $self=shift;
134 0           $self->{n}->eval(@_);
135             }
136             1;
137             __END__