I just realized I didn't answer the question directly. Here is a solution doing what you asked for. It does use some of the deep internals of the Alloy op tree though (so beware). But with a little more tweaking it would be a fine precommit hook - and then you could keep using your existing template system.
#!/usr/bin/env perl
use strict;
use warnings;
use Template::Alloy;
my $file = \ << 'EOF';
[% foo_is_not_filtered %]
[% foo_is_filtered | html %]
[% IF foo %]
[% bar %]
[% END %]
[% foo_is_none | none %]
[% BLOCK some_block %]
[% block_var %]
[% END %]
EOF
my $ta = Template::Alloy->new;
my $doc = $ta->load_template($file);
my $checker;
$checker = sub {
my $ref = shift;
return if ! ref $ref;
foreach my $node (@$ref) {
next if ! ref $node;
if ($node->[0] eq 'GET' && $node->[1] =~ /^\d+/) {
my $expr = $node->[3];
next if ! ref $expr;
my $info = $ta->node_info($node);
if (@$expr < 5 || $expr->[-3] ne '|') {
print "File \"$info->{'file'}\" line $info->{'line'}:
+No filtering ($info->{'text'})\n";
} else {
next if $expr->[-2] ne 'none'; # comment out to note e
+very filter
print "File \"$info->{'file'}\" line $info->{'line'}:
+Used $expr->[-2] filter ($info->{'text'})\n";
}
}
$checker->($_) for @$node;
}
};
local $ta->{'_component'} = $doc;
$checker->($doc->{'_tree'});
File "input text" line 8: No filtering (block_var)
File "input text" line 1: No filtering (foo_is_not_filtered)
File "input text" line 4: No filtering (bar)
File "input text" line 6: Used none filter (foo_is_none | none)
Update: If there was demand for it, I could certainly look into making this more of a first class method as part of the standard Template::Alloy distribution. Then it could more easily be reused by anybody speaking TT dialects using any TT or TA module.
my @a=qw(random brilliant braindead); print $a[rand(@a)];