lib/Template/Mustache/Trait.pm

filter: Statementstmt 100% 21 / 21 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 96.7% 30 / 31 SCAR 11.0
CC
3
Cov
96%
__ANON__
2.0
__ANON__
2.0
BEGIN
1.0
CRAP 3.0
« lib/Template/Mustache/Token/Verbatim.pm ↑ Summary script/mustache.pl »
1 package Template::Mustache::Trait;
2 1 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: turn an attribute into a Mustache template
4 1 $Template::Mustache::Trait::VERSION = '1.3.3';
5  
6 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Template::Mustache;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 before _process_options => sub {
12 2 ▶ my( $class, $name, $options ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
13  
14 2 ▶ my $default = $options->{default} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $default = $options->{"default"} or return 0 2 2
15  
16 $options->{default} = sub {
17 2 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
18 2 ▶ Template::Mustache->new(
Branch: 1 branch
BranchTrueFalseTotal
ref $default ? : 1 1 2
19 template => ref $default ? $default->($self) : $default,
20 context => $self
21 );
22 2 };
23 1 };
24  
25 package Moose::Meta::Attribute::Custom::Trait::Mustache;
26 1 our $AUTHORITY = 'cpan:YANICK';
27 1 $Moose::Meta::Attribute::Custom::Trait::Mustache::VERSION = '1.3.3';
28 1 ▶sub register_implementation { 'Template::Mustache::Trait' }
Subroutine register_implementation: called CC=1 SCAR=0.0
29  
30 1 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.3
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) 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
« lib/Template/Mustache/Token/Verbatim.pm ↑ Summary script/mustache.pl »