File: HTC_Plugin.pm

package info (click to toggle)
libhtml-template-compiled-perl 1.003-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 772 kB
  • sloc: perl: 4,759; makefile: 5
file content (92 lines) | stat: -rw-r--r-- 2,543 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use strict;
use warnings;
use Data::Dumper;
{
package # hide from CPAN =)
    HTC_Plugin1;
use HTML::Template::Compiled::Expression qw(:expressions);

HTML::Template::Compiled->register(__PACKAGE__);
sub register {
    my ($class) = @_;
    my %plugs = (
        tagnames => {
            HTML::Template::Compiled::Token::OPENING_TAG() => {
                HOMER => [sub { exists $_[1]->{BEER} }, qw(BEER)],
            },
        },
        compile => {
            HOMER => {
                open => sub {
                    my ($htc, $token, $args) = @_;
                    my $OUT = $args->{out};
                    my $attr = $token->get_attributes;
                    my $beer = $attr->{BEER};
                    my $varstr = $htc->get_compiler->parse_var($htc,
                        var => $beer,
                        method_call => $htc->method_call,
                        deref => $htc->deref,
                        formatter_path => $htc->formatter_path,
                    );
                    my $expression = _expr_literal(
                        <<"EOM"
$OUT "Homer wants " . $varstr . " beers";
EOM
                    );
                    return $expression->to_string;
                },
            },
        },
    );
    return \%plugs;
}

}

#1;
#__END__

{
package # hide from CPAN =)
    HTC_Plugin2;

use HTML::Template::Compiled::Expression qw(:expressions);
HTML::Template::Compiled->register(__PACKAGE__);
sub register {
    my ($class) = @_;
    my %plugs = (
        tagnames => {
            HTML::Template::Compiled::Token::OPENING_TAG() => {
                BART => [sub { exists $_[1]->{DONUT} }, qw(DONUT)],
            },
        },
        compile => {
            BART => {
                open => sub {
                    my ($htc, $token, $args) = @_;
                    my $OUT = $args->{out};
                    my $attr = $token->get_attributes;
                    my $beer = $attr->{DONUT};
                    my $varstr = $htc->get_compiler->parse_var($htc,
                        var => $beer,
                        method_call => $htc->method_call,
                        deref => $htc->deref,
                        formatter_path => $htc->formatter_path,
                    );
                    my $expression = _expr_literal(
                        <<"EOM"
$OUT "Bart wants " . $varstr . " donuts";
EOM
                    );
                    return $expression->to_string;
                },
            },
        },
    );
    return \%plugs;
}

}


1;