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