MooseX...e::ENV(3pm)
π MooseX::Attribute::ENV π
okay so bestie, welcome to MooseX::Attribute::ENV β a User Contributed Perl Documentation page (section 3pm, she's fancy) and literally the cutest way to make your attribute defaults come straight out of %ENV. pull up a chair. π«Ά
β¨ NAME β¨
MooseX::Attribute::ENV β set the default of an attribute to a value from %ENV. that's the whole job and she does it flawlessly. π
πΈ SYNOPSIS πΈ
here's the vibe, bestie. this is example usage for this attribute trait:
package MyApp::MyClass;
use Moose;
use MooseX::Attribute::ENV;
## Checks $ENV{username} and $ENV{USERNAME}
has 'username' => (
traits => ['ENV'],
);
## Checks $ENV{GLOBAL_PASSWORD}
has 'password' => (
traits => ['ENV'],
env_key => 'GLOBAL_PASSWORD',
);
## Checks $ENV{last_login}, $ENV{LAST_LOGIN} and then uses the default
has 'last_login' => (
traits => ['ENV'],
default => sub {localtime},
);
## Checks $ENV{XXX_config_name} and $ENV{XXX_CONFIG_NAME}
has 'config_name' => (
traits => ['ENV'],
env_prefix => 'XXX',
);
## Checks $ENV{MyApp_MyClass_extra} and $ENV{MYAPP_MYCLASS_EXTRA}
has 'extra' => (
traits => ['ENV'],
env_package_prefix => 1,
);
and please, please go peek at the test cases for more detailed examples. they ate. π₯
π¦ DESCRIPTION π¦
so this is a Moose attribute trait that you reach for when you want the default value of an attribute to be populated from the %ENV hash. iconic behaviour, honestly.
so like, for example, if you've 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';
ngl, it's 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, plus she's a simple enough attribute trait that the author hopes she can serve as a learning tool. main character energy, truly. π
and the important bit: if the named key isn't found in %ENV, then defaults will execute as normal. no cap. β¨
π ATTRIBUTES π
this role defines the following attributes.
env_key ($Str)
by default we look for a key in %ENV based on the actual attribute name. if you want or need to override this behaviour, you use this modifier. simple as. π
env_prefix ($Str)
a prefix to attach to the generated filename. the prefix is prepended with a trailing underscore. for example, if your attribute was 'attr' and you set a prefix of 'xxx' then we'd check for $ENV{xxx_attr} and $ENV{XXX_ATTR}.
env_package_prefix ($Bool)
similar to env_prefix, but automatically sets the prefix based on the consuming class's package name. so if your attribute is 'attr' and it's in a package called 'Myapp::Myclass' the following keys in %ENV will be examined:
Myapp_Myclass_attrMYAPP_MYCLASS_ATTR
β οΈ okay heads up bestie: please be aware that if you use this feature, your attribute will automatically be converted to lazy, which might affect any default subrefs you also assign to this attribute. π
π¨ and please note that you can't currently use this option along with the option'lazy_build'. that might change in a future release, however since these attributes are likely to hold simple strings thelazy_buildoption probably won't be missed. π
π§ METHODS π§
this module defines the following methods.
_process_options
overload method so that we can assign the default to be what's in %ENV. slay. β¨
π AUTHOR π
John Napiorkowski, "<jjnapiork at cpan.org>"
π BUGS π
please report any bugs or feature requests to:
C<MooseX-Attribute-ENV at rt.cpan.org>
or through the web interface at:
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Attribute-ENV>
i will be notified, and then you'll automatically be notified of progress on your bug as I make changes. we love a feedback loop. π«Ά
β SUPPORT β
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/DBIx-Class-PopulateMore
π LICENSE π
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. periodt. π
and that's the whole page, bestie!! this one's perl v5.36.0, dated 2023-01-27, and it was giving User Contributed Perl Documentation the entire time. go set some env vars and thrive. πβ¨ππ¦πΈ
π¦ where this page comes from
- debian bookworm: libmoosex-attribute-env-perl 0.02-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-attribute-env-perl 0.02-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-attribute-env-perl 0.02-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-attribute-env-perl 0.02-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-attribute-env-perl 0.02-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms