File Coverage

blib/lib/Template/Plugin/EnvHash.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 23 23 100.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Template::Plugin::EnvHash - Environment Variable Hash for TT2
4              
5             =head1 SYNOPSIS
6              
7             [% USE env = EnvHash %]
8             [% env.SOME_ENV_VAR %]
9              
10              
11             =head1 DESCRIPTION
12              
13             This is a trivial Template::Toolkit plugin to allow any template writer to suck
14             environment variables into their template. I wrote it because i was sick of
15             passing %ENV as one of the contents of the vars hash that i pass to the process
16             method of Template.
17              
18             =head1 NAMING
19              
20             I've named this module EnvHash rather than Env because most Template::Plugin::X
21             modules are wrappers around module X. Whereas this is I a wrapper around
22             Perl's Env module. This is because the purpose of that module is to export
23             environment variables into a package. I did not want to export environment
24             variables into my template as environment variables as most environment
25             variables tend to have capitalised names (by popular convention) and this might
26             cause confusion with the tt2 style of using capitalised words for its control
27             structure syntax.
28              
29             Of course someone else might come along and not care about this, so i leave
30             Template::Plugin::Env free for such a person.
31              
32             =head1 USING ENVIRONMENT VARIABLES IN TEMPLATES
33              
34             As well as this being a useful module for sucking in standard environment
35             variables it also allows you to configure template via the environment.
36              
37             Some might say using the environment variables to configure your template is
38             dangerous, and in an I i would agree. However if you
39             have a I environment it can be incredibly useful. Say for example
40             you quickly want to fire your usual apache server, but on a different port
41             (perhaps because u want to test two sets of changes simultaneous, or perhaps
42             just because someone else is using that port). Then using an environment
43             variable to pass the port number can be quick dirty and useful.
44              
45             Config files are generally better in the long run for most things, but as i say
46             it can be useful in a I environment.
47              
48             =cut
49              
50              
51              
52             package Template::Plugin::EnvHash;
53              
54              
55              
56             # pragmata
57 3     3   1269886 use 5.006;
  3         11  
  3         133  
58 3     3   18 use base qw(Template::Plugin);
  3         6  
  3         2745  
59 3     3   23414 use strict;
  3         15  
  3         96  
60 3     3   17 use warnings;
  3         8  
  3         351  
61              
62             # Standard Perl Library and CPAN modules
63              
64             our $VERSION = '1.06';
65              
66              
67             sub new {
68 18     18 1 1875920 my($class, $rh_args) = @_;
69              
70 18         25 my($self);
71              
72 18         27 $self = \%ENV;
73 18         48 bless $self, $class;
74 18         49 $self;
75             }
76              
77              
78             1;
79              
80              
81             =head1 INSTALLATION
82              
83             This module uses Module::Build for its installation. To install this module type
84             the following:
85              
86             perl Build.PL
87             ./Build
88             ./Build test
89             ./Build install
90              
91              
92             If you do not have Module::Build type:
93              
94             perl Makefile.PL
95              
96             to fetch it. Or use CPAN or CPANPLUS and fetch it "manually".
97              
98             =head1 KNOWN ISSUES
99              
100             The curernt implementation simply blesses %ENV. This causes a problem for the
101             environment variable $VERSION as this gets overwritten by the module's own
102             $VERSION. I will change the implementation at some point, but do feel free to
103             email me and hurry me along if this is stopping you from being able to use this
104             module
105              
106             Environment Variables with names begining with an underscore are not supported.
107              
108             =head1 BUGS
109              
110             To report a bug or request an enhancement use CPAN's excellent Request
111             Tracker:
112              
113             L
114              
115             =head1 SOURCE AVAILABILITY
116              
117             This source is part of a SourceForge project which always has the
118             latest sources in svn.
119              
120             http://sourceforge.net/projects/sagar-r-shah/
121              
122             =head1 AUTHOR
123              
124             Sagar R. Shah
125              
126             =head1 COPYRIGHT
127              
128             Copyright 2003-2007, Sagar R. Shah, All rights reserved
129              
130             This program is free software; you can redistribute it and/or modify it under
131             the same terms as Perl itself.
132              
133             =cut