line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Xslate::Syntax::Any; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '1.5015'; |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
249047
|
use Any::Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends qw(Text::Xslate::Parser); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has args_of_new => ( |
10
|
|
|
|
|
|
|
is => 'rw', |
11
|
|
|
|
|
|
|
isa => 'ArrayRef', |
12
|
|
|
|
|
|
|
default => sub { +[] }, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has parser_table => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
isa => 'HashRef', |
18
|
|
|
|
|
|
|
default => sub { +{} }, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
no Any::Moose; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $DETECT_SYNTAX = generate_syntax_detecter__by_suffix({ |
24
|
|
|
|
|
|
|
tx => 'Kolon', |
25
|
|
|
|
|
|
|
mtx => 'Metakolon', |
26
|
|
|
|
|
|
|
tt => 'TTerse', |
27
|
|
|
|
|
|
|
}); |
28
|
|
|
|
|
|
|
our $DEFAULT_SYNTAX = 'Kolon'; |
29
|
|
|
|
|
|
|
our $INPUT_FILTER; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
|
|
|
|
|
|
my $class = shift; |
35
|
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
36
|
|
|
|
|
|
|
$self->args_of_new([ @_ ]); |
37
|
|
|
|
|
|
|
$self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub parse { |
41
|
|
|
|
|
|
|
my($self, $input, %args) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
if($INPUT_FILTER){ |
44
|
|
|
|
|
|
|
$input = $INPUT_FILTER->($input); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
$self->_load_parser($self->compiler->file, \$input)->parse($input, %args); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _load_parser { |
50
|
|
|
|
|
|
|
my($self, $name, $input_ref) = @_; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $syntax = $DETECT_SYNTAX->($name, $input_ref); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
unless($self->parser_table->{$syntax}){ |
55
|
|
|
|
|
|
|
my $parser_class = Any::Moose::load_first_existing_class( |
56
|
|
|
|
|
|
|
"Text::Xslate::Syntax::" . $syntax, |
57
|
|
|
|
|
|
|
$syntax, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
$self->parser_table->{$syntax} = $parser_class->new(@{ $self->args_of_new }); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
return $self->parser_table->{$syntax}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub generate_syntax_detecter__by_suffix { |
65
|
|
|
|
|
|
|
my $suffx_map = shift; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub { |
68
|
|
|
|
|
|
|
my($name, undef) = @_; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my($suffix) = ($name =~ /\.([^.]+)\z/); |
71
|
|
|
|
|
|
|
$suffx_map->{$suffix || 'default'} || $DEFAULT_SYNTAX; |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
__END__ |