initial checkin
[gitmo/MooseX-Attribute-ENV.git] / lib / MooseX / Attribute / ENV.pm
1 package MooseX::Attribute::ENV;
2
3
4 =head1 NAME
5
6 MooseX::Attribute::ENV - Set default of an attribute to a value from %ENV
7
8 =head1 VERSION
9
10 Version 0.01
11
12 =cut
13
14 our $VERSION = '0.01';
15
16 =head1 SYNOPSIS
17
18 The following is example usage for this component.
19
20         package Myapp::MyClass;
21         
22         use Moose;
23         use MooseX::Attribute::ENV;
24         
25         has 'username' => (traits => ['ENV']);
26         has 'password' => (traits => ['ENV'], env_key => 'GLOBAL_PASSWORD');
27         has 'last_login' => (traits => ['ENV'], default => sub {localtime} );
28
29 Please see the test cases for more detailed examples.
30
31 =head1 DESCRIPTION
32
33 This is a L<Moose> attribute trait that you use when you want the default value
34 for an attribute to be populated from the %ENV hash.  So, for example if you
35 have set the environment variable MYAPP_MYCLASS_USERNAME = 'John' you can do:
36
37         package MyApp::MyClass;
38         
39         use Moose;
40         use MooseX::Attribute::ENV;
41         
42         has 'username' => (is=>'ro', traits=>['ENV']);
43         
44         package main;
45         
46         my $myclass = MyApp::MyClass->new();
47         
48         print $myclass->username; # STDOUT => 'John';
49
50 This is basically similar functionality to something like:
51
52         has 'attr' => (
53                 is=>'ro',
54                 default=> sub {
55                         $ENV{uc __PACKAGE_.'attr'};
56                 },
57         );
58
59 but this module has a few other features that offer merit, as well as being a
60 simple enough attribute trait that I hope it can serve as a learning tool.  It
61 also does it's best to respect existing builders, defaults and lazy_build
62 options.
63
64 =head1 METHODS
65
66 This module defines the following methods.
67
68 =head1 AUTHOR
69
70 John Napiorkowski, C<< <jjnapiork at cpan.org> >>
71
72 =head1 BUGS
73
74 Please report any bugs or feature requests to:
75
76         C<MooseX-Attribute-ENV at rt.cpan.org>
77
78 or through the web interface at:
79
80         L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Attribute-ENV>
81
82 I will be notified, and then you'll automatically be notified of progress on 
83 your bug as I make changes.
84
85 =head1 SUPPORT
86
87 You can find documentation for this module with the perldoc command.
88
89     perldoc MooseX::Attribute::ENV
90
91 You can also look for information at:
92
93 =over 4
94
95 =item * RT: CPAN's request tracker
96
97 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Attribute-ENV>
98
99 =item * AnnoCPAN: Annotated CPAN documentation
100
101 L<http://annocpan.org/dist/MooseX-Attribute-ENV>
102
103 =item * CPAN Ratings
104
105 L<http://cpanratings.perl.org/d/MooseX-Attribute-ENV>
106
107 =item * Search CPAN
108
109 L<http://search.cpan.org/dist/DBIx-Class-PopulateMore>
110
111 =back
112
113 =head1 LICENSE
114
115 This program is free software; you can redistribute it and/or modify it
116 under the same terms as Perl itself.
117
118 =cut
119
120 1;