• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/MooX/Attribute/H03-Oct-2021-17764

t/H03-Oct-2021-10283

xt/H03-Oct-2021-5139

ChangesH A D03-Oct-2021223 128

MANIFESTH A D03-Oct-2021333 1413

MANIFEST.SKIPH A D14-Mar-2019150 1312

META.jsonH A D03-Oct-20211.6 KiB6968

META.ymlH A D03-Oct-2021819 3130

Makefile.PLH A D03-Oct-20211.3 KiB5753

README.mdH A D03-Oct-20212.7 KiB9568

README.md

1# NAME
2
3MooX::Attribute::ENV - Allow Moo attributes to get their values from %ENV
4
5# PROJECT STATUS
6
7| OS      |  Build status |
8|:-------:|--------------:|
9| Linux   | [![Build Status](https://travis-ci.org/mohawk2/moox-attribute-env.svg?branch=master)](https://travis-ci.org/mohawk2/moox-attribute-env) |
10
11[![CPAN version](https://badge.fury.io/pl/moox-attribute-env.svg)](https://metacpan.org/pod/MooX::Attribute::ENV) [![Coverage Status](https://coveralls.io/repos/github/mohawk2/moox-attribute-env/badge.svg?branch=master)](https://coveralls.io/github/mohawk2/moox-attribute-env?branch=master)
12
13# SYNOPSIS
14
15    package MyMod;
16    use Moo;
17    use MooX::Attribute::ENV;
18    # look for $ENV{attr_val} and $ENV{ATTR_VAL}
19    has attr => (
20      is => 'ro',
21      env_key => 'attr_val',
22    );
23    # look for $ENV{attr_val} and $ENV{next_val}, in that order
24    has some => (
25      is => 'ro',
26      env_key => [ 'attr_val', 'next_val' ],
27    );
28    # looks for $ENV{otherattr} and $ENV{OTHERATTR}, then any default
29    has otherattr => (
30      is => 'ro',
31      env => 1,
32      default => 7,
33    );
34    # looks for $ENV{xxx_prefixattr} and $ENV{XXX_PREFIXATTR}
35    has prefixattr => (
36      is => 'ro',
37      env_prefix => 'xxx',
38    );
39    # looks for $ENV{MyMod_packageattr} and $ENV{MYMOD_PACKAGEATTR}
40    has packageattr => (
41      is => 'ro',
42      env_package_prefix => 1,
43    );
44
45    $ perl -MMyMod -E 'say MyMod->new(attr => 2)->attr'
46    # 2
47    $ ATTR_VAL=3 perl -MMyMod -E 'say MyMod->new->attr'
48    # 3
49    $ OTHERATTR=4 perl -MMyMod -E 'say MyMod->new->otherattr'
50    # 4
51
52# DESCRIPTION
53
54This is a [Moo](https://metacpan.org/pod/Moo) extension. It allows other attributes for ["has" in Moo](https://metacpan.org/pod/Moo#has). If
55any of these are given, then ["BUILDARGS" in Moo](https://metacpan.org/pod/Moo#BUILDARGS) is wrapped so that values
56for object attributes can, if not supplied in the normal construction
57process, come from the environment.
58
59The environment will be searched for either the given case, or upper case,
60version of the names discussed below.
61
62When a prefix is mentioned, it will be prepended to the mentioned name,
63with a `_` in between.
64
65# ADDITIONAL ATTRIBUTES
66
67## env
68
69Boolean. If true, the name is the attribute, no prefix.
70
71## env\_key
72
73String. If true, the name is the given value, no prefix.
74
75or
76
77ArrayRef. A list of names that will be checked in given order.
78
79## env\_prefix
80
81String. The prefix is the given value.
82
83## env\_package\_prefix
84
85Boolean. If true, use as the prefix the current package-name, with `::`
86replaced with `_`.
87
88# AUTHOR
89
90Ed J, porting John Napiorkowski's excellent [MooseX::Attribute::ENV](https://metacpan.org/pod/MooseX%3A%3AAttribute%3A%3AENV).
91
92# LICENCE
93
94The same terms as Perl itself.
95