Yes I have read about it the result is
sub parse {
# ---------------------------------------------------------------
# Parses a template.
#
my ($self, $template) = @_;
my $begin = $self->{'begin'} || quotemeta('<%');
my $end = $self->{'end'} || quotemeta('%>');
exists $self->{'templates'}{$template} or ($self->load_template($template) or return undef);
exists $self->{'vars'} or (&error ('NONAMESPACE') and return undef);
$self->{'parsed'}{$template} = '';
my $temp = $self->{'templates'}{$template};
# Parse includes, do this first so that the includes can include
# template tags.
$temp =~ s#$begin\s*include\s*(.+?)\s*$end#
if (exists $self->{'inc'}{$1}) { $self->{'inc'}{$1}; }
else {
if (open (INC, "${$self}{'ROOT'}/$1")) {
$self->{'inc'}{$1} = join ("", <INC> );
close INC;
$self->{'inc'}{$1};
}
else {
"Can't find file: ${$self}{'ROOT'}/$1";
}
}
#goe;
# Now go line by line and strip out the unwanted stuff looking for
# if and ifnot tags.
my @lines = split /\n/, $temp;
$temp = ''; my @go = (1,1); my $depth = 1; my $line = '';
LINE: foreach $line (@lines) {
# Init the previous, variable and more strings.
my ($prev, $var, $neg, $more, $orig, $full_comp, $comp, $val) = ('', '', '', '', '', '', '', '');
my $result = 0;
# Check for if tags.
$line =~ s/((.*?)$begin\s*if(not)?\s+(.+?)(\s+(<|>|lt|gt|eq|=)\s*(.+?))?$end(.*))/
($orig, $prev, $neg, $var, $full_comp, $comp, $val, $more) = ($1, $2, $3, $4, $5, $6, $7, $8);
# We've found an if tag, let's set the depth to see whether we are in print mode or not.
if ($prev !~ m,$begin\s*endif\s*$end,og) {
$go[$depth] and ($temp .= $prev);
if (!$full_comp) {
if ($neg) { ($self->{'vars'}{$var}) ? ($go[++$depth] = 0) : ($go[++$depth] = $go[$depth]) and ""; }
else { ($self->{'vars'}{$var}) ? ($go[++$depth] = $go[$depth]) : ($go[++$depth] = 0) and ""; }
}
else {
$val =~ s,^['"],,; $val =~ s,['"]$,,;
($comp eq 'eq') and ($result = ($self->{'vars'}{$var} eq $val));
($comp eq '==') and ($result = ($self->{'vars'}{$var} == $val));
($comp eq 'lt') and ($result = ($self->{'vars'}{$var} lt $val));
($comp eq 'gt') and ($result = ($self->{'vars'}{$var} gt $val));
($comp eq '>') and ($result = ($self->{'vars'}{$var} > $val));
($comp eq '<') and ($result = ($self->{'vars'}{$var} < $val));
if ($neg) { $result ? ($go[++$depth] = 0) : ($go[++$depth] = $go[$depth]) and ""; }
else { $result ? ($go[++$depth] = $go[$depth]) : ($go[++$depth] = 0) and ""; }
}
}
else {
# Oops, there was an endif tag we missed, set the original line back and keep going.
$more = ''; $orig;
}
/oe;
if ($more) { $line = $more; redo LINE; }
# Check for endif tags.
$line =~ s/(.*?)$begin\s*endif\s*$end(.*)/
($prev, $more) = ($1, $2);
$go[$depth] and ($temp .= $prev);
$go[$depth--] = 1;
"";
/oe;
if ($more) { $line = $more; redo LINE; }
# Add the content..
$go[$depth] and ($temp .= "$line\n");
}
# Replace the special variables, we allow code ref mapping.
$temp =~ s/$begin\s*(.+?)\s*$end/
if (exists $self->{'vars'}{$1}) {
ref ($self->{'vars'}{$1}) eq 'CODE' ?
&{$self->{'vars'}{$1}}($self->{'vars'}) : $self->{'vars'}{$1};
}
else { "Unkown Tag: $1"; }
/goe;
$self->{'parsed'}{$template} = $temp;
return $self->{'parsed'}{$template};
}
Is beyng copied directly over the section called
sub parse {
# ---------------------------------------------------------------
# Parses a template.
#
my $self = shift;
my $template = shift;
my $begin = $self->{'begin'} || quotemeta('<%');
my $end = $self->{'end'} || quotemeta('%>');
exists $self->{'templates'}{$template} or ($self->load_template($template) or return undef);
exists $self->{'vars'} or (&error ('NONAMESPACE') and return undef);
$self->{'parsed'}{$template} = '';
my @lines = split /\n/, $self->{'templates'}{$template};
my $go = 1;
foreach (@lines) {
/$begin\s*if\s*(.+)?\s*$end/o and ($self->{'vars'}{$1} !~ /^\s*$/) ? ($go = 1) : ($go = 0) and next;
/$begin\s*endif\s*$end/o and ($go = 1) and next;
$go or next;
s/$begin\s*(.+?)\s*$end/
if (exists $self->{'vars'}{$1}) {
ref ($self->{'vars'}{$1}) eq 'CODE' ? &{$self->{'vars'}{$1}} : $self->{'vars'}{$1};
}
else {
return "Unkown Tag: $1";
}
/goe;
$self->{'parsed'}{$template} .= $_ . "\n";
}
return $self->{'parsed'}{$template};
}
In the Template.pm file.
Trying to build this however crashes the build process.
I am using Wordpad to edit the file, and am saving it as pure text.
Help?? I would really like to get this feature operational.
sub parse {
# ---------------------------------------------------------------
# Parses a template.
#
my ($self, $template) = @_;
my $begin = $self->{'begin'} || quotemeta('<%');
my $end = $self->{'end'} || quotemeta('%>');
exists $self->{'templates'}{$template} or ($self->load_template($template) or return undef);
exists $self->{'vars'} or (&error ('NONAMESPACE') and return undef);
$self->{'parsed'}{$template} = '';
my $temp = $self->{'templates'}{$template};
# Parse includes, do this first so that the includes can include
# template tags.
$temp =~ s#$begin\s*include\s*(.+?)\s*$end#
if (exists $self->{'inc'}{$1}) { $self->{'inc'}{$1}; }
else {
if (open (INC, "${$self}{'ROOT'}/$1")) {
$self->{'inc'}{$1} = join ("", <INC> );
close INC;
$self->{'inc'}{$1};
}
else {
"Can't find file: ${$self}{'ROOT'}/$1";
}
}
#goe;
# Now go line by line and strip out the unwanted stuff looking for
# if and ifnot tags.
my @lines = split /\n/, $temp;
$temp = ''; my @go = (1,1); my $depth = 1; my $line = '';
LINE: foreach $line (@lines) {
# Init the previous, variable and more strings.
my ($prev, $var, $neg, $more, $orig, $full_comp, $comp, $val) = ('', '', '', '', '', '', '', '');
my $result = 0;
# Check for if tags.
$line =~ s/((.*?)$begin\s*if(not)?\s+(.+?)(\s+(<|>|lt|gt|eq|=)\s*(.+?))?$end(.*))/
($orig, $prev, $neg, $var, $full_comp, $comp, $val, $more) = ($1, $2, $3, $4, $5, $6, $7, $8);
# We've found an if tag, let's set the depth to see whether we are in print mode or not.
if ($prev !~ m,$begin\s*endif\s*$end,og) {
$go[$depth] and ($temp .= $prev);
if (!$full_comp) {
if ($neg) { ($self->{'vars'}{$var}) ? ($go[++$depth] = 0) : ($go[++$depth] = $go[$depth]) and ""; }
else { ($self->{'vars'}{$var}) ? ($go[++$depth] = $go[$depth]) : ($go[++$depth] = 0) and ""; }
}
else {
$val =~ s,^['"],,; $val =~ s,['"]$,,;
($comp eq 'eq') and ($result = ($self->{'vars'}{$var} eq $val));
($comp eq '==') and ($result = ($self->{'vars'}{$var} == $val));
($comp eq 'lt') and ($result = ($self->{'vars'}{$var} lt $val));
($comp eq 'gt') and ($result = ($self->{'vars'}{$var} gt $val));
($comp eq '>') and ($result = ($self->{'vars'}{$var} > $val));
($comp eq '<') and ($result = ($self->{'vars'}{$var} < $val));
if ($neg) { $result ? ($go[++$depth] = 0) : ($go[++$depth] = $go[$depth]) and ""; }
else { $result ? ($go[++$depth] = $go[$depth]) : ($go[++$depth] = 0) and ""; }
}
}
else {
# Oops, there was an endif tag we missed, set the original line back and keep going.
$more = ''; $orig;
}
/oe;
if ($more) { $line = $more; redo LINE; }
# Check for endif tags.
$line =~ s/(.*?)$begin\s*endif\s*$end(.*)/
($prev, $more) = ($1, $2);
$go[$depth] and ($temp .= $prev);
$go[$depth--] = 1;
"";
/oe;
if ($more) { $line = $more; redo LINE; }
# Add the content..
$go[$depth] and ($temp .= "$line\n");
}
# Replace the special variables, we allow code ref mapping.
$temp =~ s/$begin\s*(.+?)\s*$end/
if (exists $self->{'vars'}{$1}) {
ref ($self->{'vars'}{$1}) eq 'CODE' ?
&{$self->{'vars'}{$1}}($self->{'vars'}) : $self->{'vars'}{$1};
}
else { "Unkown Tag: $1"; }
/goe;
$self->{'parsed'}{$template} = $temp;
return $self->{'parsed'}{$template};
}
Is beyng copied directly over the section called
sub parse {
# ---------------------------------------------------------------
# Parses a template.
#
my $self = shift;
my $template = shift;
my $begin = $self->{'begin'} || quotemeta('<%');
my $end = $self->{'end'} || quotemeta('%>');
exists $self->{'templates'}{$template} or ($self->load_template($template) or return undef);
exists $self->{'vars'} or (&error ('NONAMESPACE') and return undef);
$self->{'parsed'}{$template} = '';
my @lines = split /\n/, $self->{'templates'}{$template};
my $go = 1;
foreach (@lines) {
/$begin\s*if\s*(.+)?\s*$end/o and ($self->{'vars'}{$1} !~ /^\s*$/) ? ($go = 1) : ($go = 0) and next;
/$begin\s*endif\s*$end/o and ($go = 1) and next;
$go or next;
s/$begin\s*(.+?)\s*$end/
if (exists $self->{'vars'}{$1}) {
ref ($self->{'vars'}{$1}) eq 'CODE' ? &{$self->{'vars'}{$1}} : $self->{'vars'}{$1};
}
else {
return "Unkown Tag: $1";
}
/goe;
$self->{'parsed'}{$template} .= $_ . "\n";
}
return $self->{'parsed'}{$template};
}
In the Template.pm file.
Trying to build this however crashes the build process.
I am using Wordpad to edit the file, and am saving it as pure text.
Help?? I would really like to get this feature operational.