Apache2-ASP
view release on metacpan or search on metacpan
lib/Apache2/ASP/ASPPage.pm view on Meta::CPAN
}
CODE
# Things work differently if we have/don't have a master page:
if( $s->masterpage )
{
# Sub-class the master page:
$code .= <<"CODE";
BEGIN {
(my \$pkg = '@{[ ref($s->masterpage) ]}.pm') =~ s/::/\\\\/g;
use Apache2::ASP::ASPPage;
#eval { require \$pkg; 1 } or
Apache2::ASP::ASPPage->new(
virtual_path => '@{[ $s->masterpage->virtual_path ]}'
);
}
use base '@{[ ref($s->masterpage) ]}';
use vars ( '\$Master', __PACKAGE__->VARS );
@{[ join "\n\n", map { $s->placeholder_contents->{$_} } keys(%{ $s->placeholder_contents }) ]}
@{[ join "\n\n", map { "sub $_ {\$Response->Write(q~$s->{placeholders}->{$_}~);}" } keys(%{$s->placeholders}) ]}
CODE
}
else
{
# Just sub-class this class:
$code .= <<"CODE";
use base 'Apache2::ASP::ASPPage';
use vars __PACKAGE__->VARS;
sub run {
my (\$__self,\$__context, \$__args) = \@_;
\$__self->_initialize_page;
if( my \$cached = \$__self->_read_cache )
{
\$__self->{directives}->{OutputCache} = undef;
\$Response->Write( \$cached );
return;
}# end if()
\$__context->{page} = \$__self unless \$__self->is_masterpage;
#line 1
@{[ ${$s->source_code} ]}
@{[ join "\n\n", map { "sub $_ {\$Response->Write(q~$s->{placeholders}->{$_}~);}" } keys(%{$s->placeholders}) ]}
}
CODE
}# end if()
# Finally:
$code .= <<"CODE";
1;# return true:
CODE
unlink( $s->pm_path ) if -f $s->pm_path;
open my $ofh, '>', $s->pm_path
or die "Cannot open '" . $s->pm_path . "' for writing: $!";
print $ofh $code;
close($ofh);
chmod( 0666, $s->pm_path );
}# end _assemble_code()
#==============================================================================
sub _get_directives
{
my ($s) = @_;
my $ref = $s->source_code;
my %directives = ( );
while( my ($tag, $directive, $attr_str) = $$ref =~ m/(<%@\s*(.*?)\s+(.*?)\s*%>)/ )
{
my $attrs = $s->_parse_tag_attrs( $attr_str );
$$ref =~ s/\Q$tag\E//;
$directives{$directive} = $attrs;
}# end while()
return \%directives;
}# end _get_directives()
#==============================================================================
sub _parse_tag_attrs
{
my ($s, $str) = @_;
my $attr = { };
while( $str =~ m@([^\s\=\"\']+)(\s*=\s*(?:(")(.*?)"|(')(.*?)'|([^'"\s=]+)['"]*))?@sg ) #@
{
my $key = $1;
my $test = $2;
my $val = ( $3 ? $4 : ( $5 ? $6 : $7 ));
if( $test )
{
$attr->{$key} = $val;
}
else
{
$attr->{$key} = $key;
}# end if()
}# end while()
return $attr;
}# end _parse_tag_attrs()
1;# return true:
=pod
=head1 NAME
Apache2::ASP::ASPPage - base class for all *.asp scripts
=head1 SYNOPSIS
Internal use only.
=head1 DESCRIPTION
All C<*.asp> scripts are 'compiled' down to their respective C<*.pm> files. The
( run in 0.546 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )