Banal-Moosy-Mungers
view release on metacpan or search on metacpan
lib/Banal/Moosy/Mungers.pm view on Meta::CPAN
use 5.014;
use strict;
use warnings;
package Banal::Moosy::Mungers; # git description: v0.001-4-g6edcb1b
# vim: set ts=2 sts=2 sw=2 tw=115 et :
# ABSTRACT: Provide several MUNGER functions that may be use in conjunction with C<MooseX::MungeHas>.
# KEYWORDS: Munge Has has MungeHas MooseX::MungeHas Moose MooseX Moo MooX
our $VERSION = '0.002';
# AUTHORITY
use Data::Printer; # DEBUG purposes.
use Banal::Util::Mini qw(peek tidy_arrayify);
use namespace::autoclean;
use Exporter::Shiny qw(
mhs_dict
mhs_dictionary
mhs_fallbacks
mhs_lazy_ro
mhs_specs
std_haz_mungers
);
#######################################
sub std_haz_mungers {
#######################################
our %mungers = (
haz => [ sub {; mhs_lazy_ro() } ],
haz_bool => [ sub {; mhs_lazy_ro(isa=>'Bool') } ],
haz_int => [ sub {; mhs_lazy_ro(isa=>'Int') } ],
haz_str => [ sub {; mhs_lazy_ro(isa=>'Str') } ],
haz_strs => [ sub {; mhs_lazy_ro(isa=>'ArrayRef[Str]', traits=>['Array'] ) } ],
haz_hash => [ sub {; mhs_lazy_ro(isa=>'HashRef', traits=>['Hash'] ) } ],
);
%mungers;
}
#######################################
sub mhs_fallbacks {
#######################################
require Banal::Moosy::Mungers::DeviseFallbacks;
goto &Banal::Moosy::Mungers::DeviseFallbacks::mhs_fallbacks;
}
#######################################
sub mhs_lazy_ro {
#######################################
mhs_specs( is => 'ro', init_arg => undef, lazy => 1, @_ );
}
#######################################
sub mhs_specs { # Define meta specs for attributes (is, isa, lazy, ...)
#######################################
# ATTENTION : Special calling convention and interface defined by MooseX::MungeHas.
my $name = $_; # $_ contains the attribute NAME
%_ = (@_, %_); # %_ contains the attribute SPECS, whereas @_ contains defaults (prefs) for those specs.
wantarray ? (%_) : +{%_}
}
#######################################
sub mhs_dict { &mhs_dictionary }
sub mhs_dictionary {
# - Lookup meta specs for attributes from a given (src) dictonary;
# * Parameters destined to this routine (dict, src/src_dict, dest/dest_dict) will be removed from the context.
# * Remaining parameters will win over the values looked up from the src dictionnary.
# * Current munge context (%_) wins over all of the above
# - [OPTIONALLY] : merge the resulting specs onto a given (dest) dictionary, which may the same as (serc)
#######################################
# ATTENTION : Special calling convention and interface defined by MooseX::MungeHas.
( run in 2.139 seconds using v1.01-cache-2.11-cpan-364913b4093 )