| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Template::Mustache::Trait; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
|
3
|
|
|
|
|
|
|
# ABSTRACT: turn an attribute into a Mustache template |
|
4
|
|
|
|
|
|
|
$Template::Mustache::Trait::VERSION = '1.3.4'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
673118
|
use Moose::Role; |
|
|
1
|
|
|
|
|
4823
|
|
|
|
1
|
|
|
|
|
5
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6551
|
use Template::Mustache; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
30
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
196
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
before _process_options => sub { |
|
12
|
|
|
|
|
|
|
my( $class, $name, $options ) = @_; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $default = $options->{default} or return; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$options->{default} = sub { |
|
17
|
|
|
|
|
|
|
my $self = shift; |
|
18
|
|
|
|
|
|
|
Template::Mustache->new( |
|
19
|
|
|
|
|
|
|
template => ref $default ? $default->($self) : $default, |
|
20
|
|
|
|
|
|
|
context => $self |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
}; |
|
23
|
|
|
|
|
|
|
}; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package Moose::Meta::Attribute::Custom::Trait::Mustache; |
|
26
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
|
27
|
|
|
|
|
|
|
$Moose::Meta::Attribute::Custom::Trait::Mustache::VERSION = '1.3.4'; |
|
28
|
1
|
|
|
1
|
|
1752
|
sub register_implementation { 'Template::Mustache::Trait' } |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
__END__ |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=pod |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=encoding UTF-8 |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Template::Mustache::Trait - turn an attribute into a Mustache template |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 VERSION |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
version 1.3.4 |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
package Foo; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use Moose; |
|
51
|
|
|
|
|
|
|
use Template::Mustache::Trait; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has greet => ( |
|
54
|
|
|
|
|
|
|
is => 'ro', |
|
55
|
|
|
|
|
|
|
traits => [ 'Mustache' ], |
|
56
|
|
|
|
|
|
|
default => 'Hello {{ name }}', |
|
57
|
|
|
|
|
|
|
lazy => 1, |
|
58
|
|
|
|
|
|
|
handles => { greeting => 'render' }, |
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has bye => ( |
|
62
|
|
|
|
|
|
|
is => 'ro', |
|
63
|
|
|
|
|
|
|
traits => [ 'Mustache' ], |
|
64
|
|
|
|
|
|
|
default => 'Bye {{ name }}', |
|
65
|
|
|
|
|
|
|
lazy => 1, |
|
66
|
|
|
|
|
|
|
handles => { see_ya => 'render' }, |
|
67
|
|
|
|
|
|
|
); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
has name => ( |
|
70
|
|
|
|
|
|
|
is => 'rw', |
|
71
|
|
|
|
|
|
|
default => 'world' |
|
72
|
|
|
|
|
|
|
); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# ... later on ... |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
say Foo->new->greet; # => Hello world |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This trait expects the default value to be either a Mustache template string |
|
81
|
|
|
|
|
|
|
or a function returning a template string. It will turns this template |
|
82
|
|
|
|
|
|
|
into a L<Template::Mustache> object using the parent object as its context. I.e., |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
has greet => ( |
|
85
|
|
|
|
|
|
|
is => 'ro', |
|
86
|
|
|
|
|
|
|
traits => [ 'Mustache' ], |
|
87
|
|
|
|
|
|
|
default => 'Hello {{ name }}', |
|
88
|
|
|
|
|
|
|
lazy => 1, |
|
89
|
|
|
|
|
|
|
handles => { greeting => 'render' }, |
|
90
|
|
|
|
|
|
|
); |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# equivalent to |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
has greet => ( |
|
95
|
|
|
|
|
|
|
is => 'ro', |
|
96
|
|
|
|
|
|
|
default => sub { |
|
97
|
|
|
|
|
|
|
my $self = shift; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return Template::Mustache->new( |
|
100
|
|
|
|
|
|
|
template=> 'Hello {{ name }}', |
|
101
|
|
|
|
|
|
|
context => $self |
|
102
|
|
|
|
|
|
|
); |
|
103
|
|
|
|
|
|
|
}, |
|
104
|
|
|
|
|
|
|
lazy => 1, |
|
105
|
|
|
|
|
|
|
handles => { greeting => 'render' }, |
|
106
|
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHORS |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=over 4 |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Pieter van de Bruggen <pvande@cpan.org> |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Yanick Champoux <yanick@cpan.org> |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Ricardo Signes <rjbs@cpan.org> |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=back |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This software is copyright (c) 2021, 2019, 2018, 2017, 2016, 2015, 2011 by Pieter van de Bruggen. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
131
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |