1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
MooseX-Attribute-ENV
This is a L<Moose> attribute trait that you use when you want the default value
for an attribute to be populated from the %ENV hash. So, for example if you
have set the environment variable MYAPP_MYCLASS_USERNAME = 'John' you can do:
package MyApp::MyClass;
use Moose;
use MooseX::Attribute::ENV;
has 'username' => (is=>'ro', traits=>['ENV']);
package main;
my $myclass = MyApp::MyClass->new();
print $myclass->username; # STDOUT => 'John';
This is basically similar functionality to something like:
has 'attr' => (
is=>'ro',
default=> sub {
$ENV{uc __PACKAGE_.'attr'};
},
);
but this module has a few other features that offer merit, as well as being a
simple enough attribute trait that I hope it can serve as a learning tool.
INSTALLATION
To install this module, run the following commands:
perl Makefile.PL
make
make test
make install
SUPPORT AND DOCUMENTATION
After installing, you can find documentation for this module with the
perldoc command.
perldoc MooseX-Attribute-ENV
You can also look for information at:
RT, CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Attribute-ENV
AnnoCPAN, Annotated CPAN documentation
http://annocpan.org/dist/MooseX-Attribute-ENV
CPAN Ratings
http://cpanratings.perl.org/d/MooseX-Attribute-ENV
Search CPAN
http://search.cpan.org/dist/MooseX-Attribute-ENV
COPYRIGHT AND LICENCE
Copyright (C) 2008 John Napiorkowski
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
|