package HTCForm; use strict; use warnings; use Moose; has token => (is => 'rw', isa => 'Str'); has takeme => (is => 'rw', isa => 'Str'); HTML::Template::Compiled->register(__PACKAGE__); sub register { my ($class) = @_; my %plugs = ( tagnames => { HTML::Template::Compiled::Token::OPENING_TAG() => { FORM => [sub { exists $_[1]->{NAME} }, qw/ NAME METHOD URL TOKEN /], }, HTML::Template::Compiled::Token::CLOSING_TAG() => { FORM => [undef], }, }, compile => { FORM => { open => \&open_form, close => \&close_form, }, }, ); return \%plugs; } my @stack; sub close_form { my ($htc, $token, $args) = @_; my $OUT = $args->{out}; my $token_def = pop @stack; my @defs = split /,/, $token_def; my $expression = ""; for my $def (@defs) { if ($def eq 'TAKEME') { $expression .= <<"EOM"; $OUT ' '; EOM } elsif ($def eq 'TOKEN') { $expression .= <<"EOM"; $OUT ' '; EOM } } $expression .= qq{$OUT '';\n}; return $expression; } sub open_form { my ($htc, $token, $args) = @_; my $OUT = $args->{out}; my $attr = $token->get_attributes; my $name = $attr->{NAME}; my $method = $attr->{METHOD}; my $url = $attr->{URL}; my $token = $attr->{TOKEN}; push @stack, $token; my $expression = <<"EOM"; $OUT '
'; EOM return $expression; } 1;