MooX::A...te::ENV(3)

πŸ“¦ version 0.04, in opensuse-leap 16.0

πŸ’– NAME πŸ’–

okay so this is the MooX::Attribute::ENV(3) page, coming at you from the User Contributed Perl Documentation corner of the internet. MooX::Attribute::ENV β€” allow Moo attributes to get their values from %ENV. That's the whole pitch, and it ate. πŸ’…

✨ SYNOPSIS ✨

Here's the group-chat demo, bestie:

package MyMod;
use Moo;
use MooX::Attribute::ENV;
# look for $ENV{attr_val} and $ENV{ATTR_VAL}
has attr => (
  is => 'ro',
  env_key => 'attr_val',
);
# look for $ENV{attr_val} and $ENV{next_val}, in that order
has some => (
  is => 'ro',
  env_key => [ 'attr_val', 'next_val' ],
);
# looks for $ENV{otherattr} and $ENV{OTHERATTR}, then any default
has otherattr => (
  is => 'ro',
  env => 1,
  default => 7,
);
# looks for $ENV{xxx_prefixattr} and $ENV{XXX_PREFIXATTR}
has prefixattr => (
  is => 'ro',
  env_prefix => 'xxx',
);
# looks for $ENV{MyMod_packageattr} and $ENV{MYMOD_PACKAGEATTR}
has packageattr => (
  is => 'ro',
  env_package_prefix => 1,
);

$ perl -MMyMod -E 'say MyMod->new(attr => 2)->attr'
# 2
$ ATTR_VAL=3 perl -MMyMod -E 'say MyMod->new->attr'
# 3
$ OTHERATTR=4 perl -MMyMod -E 'say MyMod->new->otherattr'
# 4

see? env vars sliding into your constructor like they own the place. πŸ’–

🌸 DESCRIPTION 🌸

This is a Moo extension. It allows other attributes for has in Moo. If any of these are given, then BUILDARGS in Moo is wrapped so that values for object attributes can, if not supplied in the normal construction process, come from the environment. no cap.

The environment will be searched for either the given case, or upper case, version of the names discussed below. So like, both versions are on the guest list. ✨

When a prefix is mentioned, it will be prepended to the mentioned name, with a _ in between. cute.

πŸ¦‹ ADDITIONAL ATTRIBUTES πŸ¦‹

πŸ“ env

Boolean. If true, the name is the attribute, no prefix. simple, iconic.

πŸ“ env_key

String. If true, the name is the given value, no prefix.

or

ArrayRef. A list of names that will be checked in given order.

πŸ“ env_prefix

String. The prefix is the given value. periodt.

πŸ“ env_package_prefix

Boolean. If true, use as the prefix the current package-name, with :: replaced with _. yup, package name gets underscore-ified. 🫢

πŸ‘‘ AUTHOR πŸ‘‘

Ed J, porting John Napiorkowski's excellent MooseX::Attribute::ENV.

🌈 LICENCE 🌈

The same terms as Perl itself.


okay bestie, that's the whole manual page. sign-off time: this was the perl v5.42.0 version, dated 2021-10-04. slay, bye! πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from