File Coverage

blib/lib/Dotiac/DTL/Tag/block.pm
Criterion Covered Total %
statement 107 111 96.4
branch 12 14 85.7
condition n/a
subroutine 15 16 93.7
pod 11 11 100.0
total 145 152 95.3


line stmt bran cond sub pod time code
1             #block.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             #block.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            
17             package Dotiac::DTL::Tag::block;
18 11     11   56 use base qw/Dotiac::DTL::Tag/;
  11         22  
  11         782  
19 11     11   56 use strict;
  11         25  
  11         300  
20 11     11   51 use warnings;
  11         27  
  11         1610  
21            
22             our $VERSION = 0.8;
23            
24             sub new {
25 6     6 1 13 my $class=shift;
26 6         19 my $self={p=>shift()};
27 6         10 my $name=shift;
28 6 50       15 die "This block needs a name" unless $name;
29 6         15 $self->{name}=$name;
30 6         10 my $obj=shift;
31 6         8 my $data=shift;
32 6         9 my $pos=shift;
33 6         9 my $found="";
34 6         23 $self->{content}=$obj->parse($data,$pos,\$found,"endblock");
35 6         18 bless $self,$class;
36 6         20 return $self;
37             }
38             sub print {
39 14     14 1 52 my $self=shift;
40 14         102 print $self->{p};
41 14         24 my $vars=shift;
42 11     11   67 use Carp;
  11         17  
  11         12726  
43             #confess;
44 14 100       42 if ($Dotiac::DTL::blocks{$self->{name}}) {
45             #confess ref $Dotiac::DTL::blocks{$self->{name}}->[0];
46 12 100       57 $Dotiac::DTL::blocks{$self->{name}}->[0]->print({%{$vars},"block.super",$self->{content}},@_) unless ref $Dotiac::DTL::blocks{$self->{name}}->[0] eq "REF" ;
  6         40  
47 12 100       54 print ${$Dotiac::DTL::blocks{$self->{name}}->[0]}->({%{$vars},"block.super",$self->{content}},@_) if ref $Dotiac::DTL::blocks{$self->{name}}->[0] eq "REF" ;
  6         23  
  6         27  
48             }
49             else {
50 2         9 $self->{content}->print($vars,@_);
51             }
52 14         123 $self->{n}->print($vars,@_);
53             }
54             sub string {
55 14     14 1 74 my $self=shift;
56 14         26 my $vars=shift;
57 14 100       49 if ($Dotiac::DTL::blocks{$self->{name}}) {
58             #use Carp;
59             #confess "No Var" unless $vars;
60            
61 12 100       52 return $self->{p}.${$Dotiac::DTL::blocks{$self->{name}}->[0]}->({%{$vars},"block.super",$self->{content}},@_).$self->{n}->string($vars,@_) if ref $Dotiac::DTL::blocks{$self->{name}}->[0] eq "REF";
  6         25  
  6         30  
62 6         36 return $self->{p}.$Dotiac::DTL::blocks{$self->{name}}->[0]->string({%{$vars},"block.super",$self->{content}},@_).$self->{n}->string($vars,@_);
  6         66  
63             }
64 2         9 return $self->{p}.$self->{content}->string($vars,@_).$self->{n}->string($vars,@_);
65            
66             }
67             sub perlcount {
68 0     0 1 0 my $self=shift;
69 0         0 my $id=shift;
70 0         0 $id=$self->{content}->perlcount($id+1,@_);
71 0         0 return $self->{n}->perlcount($id+1);
72             }
73             sub perl {
74 14     14 1 24 my $self=shift;
75 14         21 my $fh=shift;
76 14         20 my $id=shift;
77 14         56 $self->SUPER::perl($fh,$id,@_);
78 14         39 print $fh "my \$ssub$id = sub {return ''};\n";
79 14         38 print $fh "my \$sub$id = \\\$ssub$id;\n";
80 14         21 print $fh "my ";
81 14         242 print $fh (Data::Dumper->Dump([$self->{name}],["\$name$id"]));
82 14         582 $id=$self->{content}->perl($fh,$id+1,@_);
83 14         62 return $self->{n}->perl($fh,$id+1,@_);
84             }
85             sub perlinit {
86 14     14 1 23 my $self=shift;
87 14         16 my $fh=shift;
88 14         22 my $id=shift;
89 14         32 print $fh "\$ssub$id=sub {\n";
90 14         21 print $fh "\tmy \$vars=shift();\n";
91 14         18 print $fh "\tmy \$escape=shift();\n";
92 14         21 print $fh "\tmy \$r=\"\";\n";
93 14         67 my $nid=$self->{content}->perlstring($fh,$id+1,1,@_);
94 14         29 print $fh "\treturn \$r;\n";
95 14         24 print $fh "};\n";
96 14         55 $id=$self->{content}->perlinit($fh,$id+1,@_);
97 14         50 return $self->{n}->perlinit($fh,$id+1,@_);
98             }
99             sub perlprint {
100 4     4 1 7 my $self=shift;
101 4         8 my $fh=shift;
102 4         5 my $id=shift;
103 4         6 my $level=shift;
104 4         18 $self->SUPER::perlprint($fh,$id,$level,@_);
105 4         13 print $fh "\t" x $level,"if (\$Dotiac::DTL::blocks{\$name$id}) {\n";
106 4         14 print $fh "\t" x $level,"\tprint \${\$Dotiac::DTL::blocks{\$name$id}->[0]}->({\%{\$vars},\"block.super\",\$ssub$id},\$escape,\@_) if ref \$Dotiac::DTL::blocks{\$name$id}->[0] eq 'REF';\n"; #Might a perlstring routine....
107 4         15 print $fh "\t" x $level,"\t\$Dotiac::DTL::blocks{\$name$id}->[0]->print({\%{\$vars},\"block.super\",\$ssub$id},\$escape,\@_) unless ref \$Dotiac::DTL::blocks{\$name$id}->[0] eq 'REF';\n"; #Might a perlstring routine....
108 4         7 print $fh "\t" x $level,"} else {\n";
109 4         17 my $nid=$self->{content}->perlprint($fh,$id+1,$level+1,@_);
110 4         10 print $fh "\t" x $level,"}\n";
111 4         17 return $self->{n}->perlprint($fh,$nid+1,$level,@_);
112            
113             }
114             sub perlstring {
115 4     4 1 8 my $self=shift;
116 4         7 my $fh=shift;
117 4         5 my $id=shift;
118 4         5 my $level=shift;
119 4         19 $self->SUPER::perlstring($fh,$id,$level,@_);
120 11 50   11   73 use Carp; confess unless $level;
  11         32  
  11         31061  
  4         12  
121 4         14 print $fh "\t" x $level,"if (\$Dotiac::DTL::blocks{\$name$id}) {\n";
122             #print $fh "\t" x $level,"\t\$r.=\${\$Dotiac::DTL::blocks{\$name$id}}->({\%{\$vars},\"block.super\",\$ssub$id},\$escape,\@_);\n"; #Might a perlstring routine....
123 4         15 print $fh "\t" x $level,"\t\$r.=\${\$Dotiac::DTL::blocks{\$name$id}->[0]}->({\%{\$vars},\"block.super\",\$ssub$id},\$escape,\@_) if ref \$Dotiac::DTL::blocks{\$name$id}->[0] eq 'REF';\n"; #Might a perlstring routine....
124 4         14 print $fh "\t" x $level,"\t\$r.=\$Dotiac::DTL::blocks{\$name$id}->[0]->string({\%{\$vars},\"block.super\",\$ssub$id},\$escape,\@_) unless ref \$Dotiac::DTL::blocks{\$name$id}->[0] eq 'REF';\n"; #Might a perlstring routine....
125 4         8 print $fh "\t" x $level,"} else {\n";
126 4         16 my $nid=$self->{content}->perlstring($fh,$id+1,$level+1,@_);
127 4         10 print $fh "\t" x $level,"}\n";
128 4         17 return $self->{n}->perlstring($fh,$nid+1,$level,@_);
129             }
130             sub perleval {
131 34     34 1 47 my $self=shift;
132 34         52 my $fh=shift;
133 34         39 my $id=shift;
134 34         38 my $level=shift;
135 34         91 print $fh "\t" x $level,"unshift \@{\$Dotiac::DTL::blocks{\$name$id}},\$sub$id;\n";
136 34         117 $id=$self->{content}->perleval($fh,$id+1,$level,@_);
137 34         100 return $self->{n}->perleval($fh,$id+1,$level);
138             }
139             sub next {
140 6     6 1 10 my $self=shift;
141 6         25 $self->{n}=shift;
142             }
143             sub eval {
144 20     20 1 29 my $self=shift;
145 20         27 unshift @{$Dotiac::DTL::blocks{$self->{name}}},$self->{content};
  20         83  
146 20         109 $self->{n}->eval(@_);
147             }
148             1;
149            
150             __END__