Apache-XPP

 view release on metacpan or  search on metacpan

lib/Apache/XPP/PreParse.pm  view on Meta::CPAN

=head1 NAME

Apache::XPP::PreParse - XPP TAG Parser

=cut

=head1 SYNOPSIS

 use Apache::XPP::PreParse;
 $preparsers	= Apache::XPP::PreParse->parsers;
 foreach (@{ $preparsers }) {
 	$preparsers->( \$text );
 }

=head1 REQUIRES

Nothing

=head1 EXPORTS

Nothing

=cut

package Apache::XPP::PreParse;

use Carp;
use strict;
use vars qw($AUTOLOAD @parsers $debug );

BEGIN {
	$Apache::XPP::PreParse::REVISION       = (qw$Revision: 1.19 $)[-1];
	$Apache::XPP::PreParse::VERSION        = '2.01';

	$debug		= undef;
	@parsers	= qw( parser_xppcomment parser_xppcache parser_xppxinclude
		parser_print parser_appmethod parser_xppforeach parser_xppshift
		parser_xppwhile );
}

=head1 DESCRIPTION

Apache::XPP::PreParse handles pre parsing of an xpp page to convert 'tags' into valid 
XPML. Tags are meant as a shortcut for code that might otherwise be burdensome or 
confusing for and xpml author, such as ref checking before calling a method: 
<xpp method="cities_popup_menu" obj="$app"> might be converted to: 
<?xpp if (ref($app)) { print $app->cities_popup_menu; } ?>.

=head1 METHODS

=over

=item C<parsers> (  )

Returns a new parser object

=cut
sub parsers {
	my $self = shift;
	my $class = ref($self) || $self;
	no strict 'refs';
	return \@{"${class}::parsers"};
} # END method parsers


=item C<add_parser> ( \&parser )

Adds a parser to the list of registered pre-parsers.

=cut
sub add_parser {
	my $proto		= shift;
	my $class		= ref($proto) || $proto;
	my $parser		= shift;
	push(@parsers, $parser);
} # END method add_parser

=item C<parse_tag> ( $tag )

Given an xpp TAG $tag, will return an array with two elements.
The first element is an array reference of the order of keys in
the tag. The second element is a hash reference to the key-value
pairs.

=cut
sub parse_tag {
	my $proto	= shift;
	my $class	= ref($proto) || $proto;
	my $tag		= shift;
	if ($tag =~ m/\<(.+)?\>/s) {
		my $tagcontent	= $1;
		warn "CONTENT: $tagcontent" if ($debug >= 2);
		my (@keys, %data);
		while ($tagcontent =~ s/^(?:\s*)([^=\s]+)(?:\="(.*?)")?//so) {
			push(@keys, $1);
			$data{ $1 }	= $2;
		}
		
		return (\@keys, \%data);
	} else {
		return undef;
	}
} # END method parse_tag

=item C<dtag> ( \$text, $tag, $subref )

This is for processing tags with a start tag and seperate end tag.



( run in 0.769 second using v1.01-cache-2.11-cpan-364913b4093 )