sub
new {
my
$class
=
shift
;
my
$self
={
p
=>
shift
()};
my
$name
=
shift
;
die
"This block needs a name"
unless
$name
;
$self
->{name}=
$name
;
my
$obj
=
shift
;
my
$data
=
shift
;
my
$pos
=
shift
;
my
$found
=
""
;
$self
->{content}=
$obj
->parse(
$data
,
$pos
,\
$found
,
"endblock"
);
bless
$self
,
$class
;
return
$self
;
}
sub
print
{
my
$self
=
shift
;
print
$self
->{p};
my
$vars
=
shift
;
if
(
$Dotiac::DTL::blocks
{
$self
->{name}}) {
$Dotiac::DTL::blocks
{
$self
->{name}}->[0]->
print
({%{
$vars
},
"block.super"
,
$self
->{content}},
@_
)
unless
ref
$Dotiac::DTL::blocks
{
$self
->{name}}->[0] eq
"REF"
;
print
${
$Dotiac::DTL::blocks
{
$self
->{name}}->[0]}->({%{
$vars
},
"block.super"
,
$self
->{content}},
@_
)
if
ref
$Dotiac::DTL::blocks
{
$self
->{name}}->[0] eq
"REF"
;
}
else
{
$self
->{content}->
print
(
$vars
,
@_
);
}
$self
->{n}->
print
(
$vars
,
@_
);
}
sub
string {
my
$self
=
shift
;
my
$vars
=
shift
;
if
(
$Dotiac::DTL::blocks
{
$self
->{name}}) {
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"
;
return
$self
->{p}.
$Dotiac::DTL::blocks
{
$self
->{name}}->[0]->string({%{
$vars
},
"block.super"
,
$self
->{content}},
@_
).
$self
->{n}->string(
$vars
,
@_
);
}
return
$self
->{p}.
$self
->{content}->string(
$vars
,
@_
).
$self
->{n}->string(
$vars
,
@_
);
}
sub
perlcount {
my
$self
=
shift
;
my
$id
=
shift
;
$id
=
$self
->{content}->perlcount(
$id
+1,
@_
);
return
$self
->{n}->perlcount(
$id
+1);
}
sub
perl {
my
$self
=
shift
;
my
$fh
=
shift
;
my
$id
=
shift
;
$self
->SUPER::perl(
$fh
,
$id
,
@_
);
print
$fh
"my \$ssub$id = sub {return ''};\n"
;
print
$fh
"my \$sub$id = \\\$ssub$id;\n"
;
print
$fh
"my "
;
print
$fh
(Data::Dumper->Dump([
$self
->{name}],[
"\$name$id"
]));
$id
=
$self
->{content}->perl(
$fh
,
$id
+1,
@_
);
return
$self
->{n}->perl(
$fh
,
$id
+1,
@_
);
}
sub
perlinit {
my
$self
=
shift
;
my
$fh
=
shift
;
my
$id
=
shift
;
print
$fh
"\$ssub$id=sub {\n"
;
print
$fh
"\tmy \$vars=shift();\n"
;
print
$fh
"\tmy \$escape=shift();\n"
;
print
$fh
"\tmy \$r=\"\";\n"
;
my
$nid
=
$self
->{content}->perlstring(
$fh
,
$id
+1,1,
@_
);
print
$fh
"\treturn \$r;\n"
;
print
$fh
"};\n"
;
$id
=
$self
->{content}->perlinit(
$fh
,
$id
+1,
@_
);
return
$self
->{n}->perlinit(
$fh
,
$id
+1,
@_
);
}
sub
perlprint {
my
$self
=
shift
;
my
$fh
=
shift
;
my
$id
=
shift
;
my
$level
=
shift
;
$self
->SUPER::perlprint(
$fh
,
$id
,
$level
,
@_
);
print
$fh
"\t"
x
$level
,
"if (\$Dotiac::DTL::blocks{\$name$id}) {\n"
;
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"
;
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"
;
print
$fh
"\t"
x
$level
,
"} else {\n"
;
my
$nid
=
$self
->{content}->perlprint(
$fh
,
$id
+1,
$level
+1,
@_
);
print
$fh
"\t"
x
$level
,
"}\n"
;
return
$self
->{n}->perlprint(
$fh
,
$nid
+1,
$level
,
@_
);
}
sub
perlstring {
my
$self
=
shift
;
my
$fh
=
shift
;
my
$id
=
shift
;
my
$level
=
shift
;
$self
->SUPER::perlstring(
$fh
,
$id
,
$level
,
@_
);
use
Carp ; confess
unless
$level
;
print
$fh
"\t"
x
$level
,
"if (\$Dotiac::DTL::blocks{\$name$id}) {\n"
;
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"
;
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"
;
print
$fh
"\t"
x
$level
,
"} else {\n"
;
my
$nid
=
$self
->{content}->perlstring(
$fh
,
$id
+1,
$level
+1,
@_
);
print
$fh
"\t"
x
$level
,
"}\n"
;
return
$self
->{n}->perlstring(
$fh
,
$nid
+1,
$level
,
@_
);
}
sub
perleval {
my
$self
=
shift
;
my
$fh
=
shift
;
my
$id
=
shift
;
my
$level
=
shift
;
print
$fh
"\t"
x
$level
,
"unshift \@{\$Dotiac::DTL::blocks{\$name$id}},\$sub$id;\n"
;
$id
=
$self
->{content}->perleval(
$fh
,
$id
+1,
$level
,
@_
);
return
$self
->{n}->perleval(
$fh
,
$id
+1,
$level
);
}
sub
next
{
my
$self
=
shift
;
$self
->{n}=
shift
;
}
sub
eval
{
my
$self
=
shift
;
unshift
@{
$Dotiac::DTL::blocks
{
$self
->{name}}},
$self
->{content};
$self
->{n}->
eval
(
@_
);
}
1;
Hide Show 107 lines of Pod