1 package MooseX::Attribute::ENV;
6 MooseX::Attribute::ENV - Set default of an attribute to a value from %ENV
14 our $VERSION = '0.01';
18 The following is example usage for this component.
20 package Myapp::MyClass;
23 use MooseX::Attribute::ENV;
25 has 'username' => (traits => ['ENV']);
26 has 'password' => (traits => ['ENV'], env_key => 'GLOBAL_PASSWORD');
27 has 'last_login' => (traits => ['ENV'], default => sub {localtime} );
29 Please see the test cases for more detailed examples.
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:
37 package MyApp::MyClass;
40 use MooseX::Attribute::ENV;
42 has 'username' => (is=>'ro', traits=>['ENV']);
46 my $myclass = MyApp::MyClass->new();
48 print $myclass->username; # STDOUT => 'John';
50 This is basically similar functionality to something like:
55 $ENV{uc __PACKAGE_.'attr'};
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
66 This module defines the following methods.
70 John Napiorkowski, C<< <jjnapiork at cpan.org> >>
74 Please report any bugs or feature requests to:
76 C<MooseX-Attribute-ENV at rt.cpan.org>
78 or through the web interface at:
80 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Attribute-ENV>
82 I will be notified, and then you'll automatically be notified of progress on
83 your bug as I make changes.
87 You can find documentation for this module with the perldoc command.
89 perldoc MooseX::Attribute::ENV
91 You can also look for information at:
95 =item * RT: CPAN's request tracker
97 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Attribute-ENV>
99 =item * AnnoCPAN: Annotated CPAN documentation
101 L<http://annocpan.org/dist/MooseX-Attribute-ENV>
105 L<http://cpanratings.perl.org/d/MooseX-Attribute-ENV>
109 L<http://search.cpan.org/dist/DBIx-Class-PopulateMore>
115 This program is free software; you can redistribute it and/or modify it
116 under the same terms as Perl itself.