File Coverage

blib/lib/Dotiac/DTL/Tag/filter.pm
Criterion Covered Total %
statement 80 87 91.9
branch 2 4 50.0
condition n/a
subroutine 12 14 85.7
pod 11 11 100.0
total 105 116 90.5


line stmt bran cond sub pod time code
1             #filter.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             #filter.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::filter;
17 11     11   56 use base qw/Dotiac::DTL::Tag/;
  11         32  
  11         8006  
18 11     11   80 use strict;
  11         22  
  11         4199  
19 11     11   78 use warnings;
  11         28  
  11         12200  
20            
21             our $VERSION = 0.8;
22            
23             sub new {
24 3     3 1 7 my $class=shift;
25 3         10 my $self={p=>shift()};
26 3         5 my $name=shift;
27 3 50       12 die "This filter needs some filters" unless $name;
28 3         15 my @name=Dotiac::DTL::get_variables($name);
29 3         16 $self->{filters}=[split /\|/,$name[0]];
30 3         6 my $obj=shift;
31 3         5 my $data=shift;
32 3         6 my $pos=shift;
33 3         6 my $found="";
34 3         21 $self->{content}=$obj->parse($data,$pos,\$found,"endfilter");
35 3         9 bless $self,$class;
36 3         13 return $self;
37             }
38             sub print {
39 3     3 1 6 my $self=shift;
40 3         37 print $self->{p};
41 3         7 my $vars=shift;
42 3         6 my $escape=shift;
43 3         16 print Dotiac::DTL::apply_filters($self->{content}->string($vars,$escape,@_),$vars,0,@{$self->{filters}})->string();
  3         14  
44 3         22 $self->{n}->print($vars,$escape,@_);
45             }
46             sub string {
47 3     3 1 6 my $self=shift;
48 3         16 my $vars=shift;
49 3         5 my $escape=shift;
50 3         19 return $self->{p}.Dotiac::DTL::apply_filters($self->{content}->string($vars,$escape,@_),$vars,0,@{$self->{filters}})->string().$self->{n}->string($vars,$escape,@_);
  3         17  
51            
52             }
53             sub perl {
54 3     3 1 7 my $self=shift;
55 3         6 my $fh=shift;
56 3         6 my $id=shift;
57 3         23 $self->SUPER::perl($fh,$id,@_);
58 3         5 print $fh "my ";
59 3         20 print $fh (Data::Dumper->Dump([$self->{filters}],["\$filters$id"]));
60 3         155 $id=$self->{content}->perl($fh,$id+1,@_);
61 3 50       26 return $self->{n}->perl($fh,$id+1,@_) if $self->{n};
62 0         0 return $id;
63             }
64             sub perlprint {
65 3     3 1 9 my $self=shift;
66 3         6 my $fh=shift;
67 3         5 my $id=shift;
68 3         5 my $level=shift;
69 3         20 $self->SUPER::perlprint($fh,$id,$level,@_);
70 3         8 my $in="\t" x $level;
71 3         5 print $fh $in,"{\n";
72 3         6 print $fh $in,"\tmy \$r=\"\";\n";
73 3         14 my $nid = $self->{content}->perlstring($fh,$id+1,$level+1,@_);
74 3         13 print $fh $in,"\tprint Dotiac::DTL::apply_filters(\$r,\$vars,0,\@{\$filters$id},\@_)->string();\n";
75 3         7 print $fh $in,"}\n";
76 3         12 return $self->{n}->perlprint($fh,$nid+1,$level,@_);
77             }
78             sub perlstring {
79 3     3 1 8 my $self=shift;
80 3         6 my $fh=shift;
81 3         5 my $id=shift;
82 3         6 my $level=shift;
83 3         23 $self->SUPER::perlstring($fh,$id,$level,@_);
84 3         7 my $in="\t" x $level;
85 3         11 print $fh $in,"my \$v$id=\"\";\n";
86 3         5 print $fh $in,"{\n";
87 3         8 print $fh $in,"\tmy \$r=\"\";\n";
88 3         18 my $nid = $self->{content}->perlstring($fh,$id+1,$level+1,@_);
89 3         8 print $fh $in,"\t\$v$id=\$r;\n";
90 3         7 print $fh $in,"}\n";
91 3         12 print $fh $in,"\$r.=Dotiac::DTL::apply_filters(\$v$id,\$vars,0,\@{\$filters$id})->string();\n";
92 3         28 return $self->{n}->perlstring($fh,$nid+1,$level,@_);
93             }
94             sub perlcount {
95 0     0 1 0 my $self=shift;
96 0         0 my $id=shift;
97 0         0 $id = $self->{content}->perlcount($id+1);
98 0         0 return $self->{n}->perlcount($id+1);
99             }
100             sub perleval {
101 3     3 1 8 my $self=shift;
102 3         6 my $fh=shift;
103 3         4 my $id=shift;
104 3         27 $id=$self->{content}->perleval($fh,$id+1,@_);
105 3         14 return $self->{n}->perleval($fh,$id+1,@_);
106             }
107             sub perlinit {
108 3     3 1 8 my $self=shift;
109 3         5 my $fh=shift;
110 3         5 my $id=shift;
111 3         19 $id=$self->{content}->perlinit($fh,$id+1,@_);
112 3         15 return $self->{n}->perlinit($fh,$id+1,@_);
113             }
114             sub next {
115 3     3 1 4 my $self=shift;
116 3         25 $self->{n}=shift;
117             }
118             sub eval {
119 0     0 1   my $self=shift;
120 0           $self->{n}->eval(@_);
121             }
122             1;
123            
124             __END__