File Coverage

lib/Petal/Hash/Test.pm
Criterion Covered Total %
statement 10 10 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 14 14 100.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Petal::Hash::Test - Test and Tutorial Petal modifier
4              
5             =head1 SUMMARY
6              
7             Petal modifiers are snippets of code which are used to extend the
8             expression engine capabilities. This test shows how to write your
9             own modifiers.
10              
11             =head1 API
12              
13             The modifier API is very, very simple. It consists of two elements:
14              
15             =head2 The package name
16              
17             Your modifier should be called Petal::Hash::, where
18             is the name that you want to give to your modifier.
19              
20             For example, this modifier is called Petal::Hash::Test. Petal will
21             automatically pick it the module up and assign it the 'test:' prefix.
22              
23             package Petal::Hash::Test;
24             use warnings;
25             use strict;
26              
27             =cut
28             package Petal::Hash::Test;
29 77     77   493 use warnings;
  77         166  
  77         2606  
30 77     77   389 use strict;
  77         111  
  77         5858  
31              
32              
33             =head2 The method $class->process ($hash, $argument);
34              
35             This class method will define the modifier in itself.
36              
37             * $class is the package name of your modifier (which might come in
38             handy if you're subclassing a modifier),
39              
40             * $hash is the execution context, i.e. the objects and data which
41             will 'fill' your template,
42              
43             * $argument is whatever was after your modifier's prefix. For example,
44             for the expression 'test:foo bar', $argument would be 'foo bar'.
45              
46             In this test / tutorial we're going to write a modifier which
47             uppercases a Petal expression.
48              
49             sub process
50             {
51             my $class = shift;
52             my $hash = shift;
53             my $argument = shift;
54              
55             return uc ($hash->get ($argument));
56             }
57              
58             1;
59              
60             __END__
61              
62             And that's it! Simple!
63              
64             =cut
65             sub process
66             {
67 1     1 1 3 my $class = shift;
68 1         2 my $hash = shift;
69 1         1 my $argument = shift;
70              
71 1         5 return uc ($hash->get ($argument));
72             }
73              
74              
75             1;
76              
77              
78             __END__