This is a 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 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 '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.
If the named key isn't found in %ENV, then defaults will execute as normal.
Package Version | Update ID | Released | Package Hub Version | Platforms | Subpackages |
---|---|---|---|---|---|
0.02-bp156.3.1 info | GA Release | 2023-07-22 | 15 SP6 |
|
|
0.02-bp155.2.8 info | GA Release | 2023-05-17 | 15 SP5 |
|
|
0.02-bp154.1.17 info | GA Release | 2022-05-09 | 15 SP4 |
|
|
0.02-bp153.1.12 info | GA Release | 2021-03-06 | 15 SP3 |
|
|
0.02-bp152.3.13 info | GA Release | 2020-04-17 | 15 SP2 |
|
|
0.02-bp151.3.1 info | GA Release | 2019-07-17 | 15 SP1 |
|
|
0.02-bp151.2.10 info | GA Release | 2019-05-18 | 15 SP1 |
|
|
0.02-bp150.2.4 info | GA Release | 2018-07-30 | 15 |
|
|