Initial Commit
This commit is contained in:
228
database/perl/vendor/lib/Moo/HandleMoose.pm
vendored
Normal file
228
database/perl/vendor/lib/Moo/HandleMoose.pm
vendored
Normal file
@@ -0,0 +1,228 @@
|
||||
package Moo::HandleMoose;
|
||||
use Moo::_strictures;
|
||||
use Moo::_Utils qw(_getstash);
|
||||
use Sub::Quote qw(quotify);
|
||||
use Carp qw(croak);
|
||||
|
||||
our %TYPE_MAP;
|
||||
|
||||
our $SETUP_DONE;
|
||||
|
||||
sub import { return if $SETUP_DONE; inject_all(); $SETUP_DONE = 1; }
|
||||
|
||||
sub inject_all {
|
||||
croak "Can't inflate Moose metaclass with Moo::sification disabled"
|
||||
if $Moo::sification::disabled;
|
||||
require Class::MOP;
|
||||
inject_fake_metaclass_for($_)
|
||||
for grep $_ ne 'Moo::Object', keys %Moo::MAKERS;
|
||||
inject_fake_metaclass_for($_) for keys %Moo::Role::INFO;
|
||||
require Moose::Meta::Method::Constructor;
|
||||
@Moo::HandleMoose::FakeConstructor::ISA = 'Moose::Meta::Method::Constructor';
|
||||
@Moo::HandleMoose::FakeMeta::ISA = 'Moose::Meta::Method::Meta';
|
||||
}
|
||||
|
||||
sub maybe_reinject_fake_metaclass_for {
|
||||
my ($name) = @_;
|
||||
our %DID_INJECT;
|
||||
if (delete $DID_INJECT{$name}) {
|
||||
unless ($Moo::Role::INFO{$name}) {
|
||||
Moo->_constructor_maker_for($name)->install_delayed;
|
||||
}
|
||||
inject_fake_metaclass_for($name);
|
||||
}
|
||||
}
|
||||
|
||||
sub inject_fake_metaclass_for {
|
||||
my ($name) = @_;
|
||||
require Class::MOP;
|
||||
require Moo::HandleMoose::FakeMetaClass;
|
||||
Class::MOP::store_metaclass_by_name(
|
||||
$name, bless({ name => $name }, 'Moo::HandleMoose::FakeMetaClass')
|
||||
);
|
||||
require Moose::Util::TypeConstraints;
|
||||
if ($Moo::Role::INFO{$name}) {
|
||||
Moose::Util::TypeConstraints::find_or_create_does_type_constraint($name);
|
||||
} else {
|
||||
Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($name);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
package Moo::HandleMoose::FakeConstructor;
|
||||
|
||||
sub _uninlined_body { \&Moose::Object::new }
|
||||
}
|
||||
|
||||
sub inject_real_metaclass_for {
|
||||
my ($name) = @_;
|
||||
our %DID_INJECT;
|
||||
return Class::MOP::get_metaclass_by_name($name) if $DID_INJECT{$name};
|
||||
require Moose; require Moo; require Moo::Role; require Scalar::Util;
|
||||
require Sub::Defer;
|
||||
Class::MOP::remove_metaclass_by_name($name);
|
||||
my ($am_role, $am_class, $meta, $attr_specs, $attr_order) = do {
|
||||
if (my $info = $Moo::Role::INFO{$name}) {
|
||||
my @attr_info = @{$info->{attributes}||[]};
|
||||
(1, 0, Moose::Meta::Role->initialize($name),
|
||||
{ @attr_info },
|
||||
[ @attr_info[grep !($_ % 2), 0..$#attr_info] ]
|
||||
)
|
||||
} elsif ( my $cmaker = Moo->_constructor_maker_for($name) ) {
|
||||
my $specs = $cmaker->all_attribute_specs;
|
||||
(0, 1, Moose::Meta::Class->initialize($name), $specs,
|
||||
[ sort { $specs->{$a}{index} <=> $specs->{$b}{index} } keys %$specs ]
|
||||
);
|
||||
} else {
|
||||
# This codepath is used if $name does not exist in $Moo::MAKERS
|
||||
(0, 0, Moose::Meta::Class->initialize($name), {}, [] )
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
local $DID_INJECT{$name} = 1;
|
||||
foreach my $spec (values %$attr_specs) {
|
||||
if (my $inflators = delete $spec->{moosify}) {
|
||||
$_->($spec) for @$inflators;
|
||||
}
|
||||
}
|
||||
|
||||
my %methods
|
||||
= %{($am_role ? 'Moo::Role' : 'Moo')->_concrete_methods_of($name)};
|
||||
|
||||
# if stuff gets added afterwards, _maybe_reset_handlemoose should
|
||||
# trigger the recreation of the metaclass but we need to ensure the
|
||||
# Moo::Role cache is cleared so we don't confuse Moo itself.
|
||||
if (my $info = $Moo::Role::INFO{$name}) {
|
||||
delete $info->{methods};
|
||||
}
|
||||
|
||||
# needed to ensure the method body is stable and get things named
|
||||
$methods{$_} = Sub::Defer::undefer_sub($methods{$_})
|
||||
for
|
||||
grep $_ ne 'new',
|
||||
keys %methods;
|
||||
my @attrs;
|
||||
{
|
||||
# This local is completely not required for roles but harmless
|
||||
local @{_getstash($name)}{keys %methods};
|
||||
my %seen_name;
|
||||
foreach my $attr_name (@$attr_order) {
|
||||
$seen_name{$attr_name} = 1;
|
||||
my %spec = %{$attr_specs->{$attr_name}};
|
||||
my %spec_map = (
|
||||
map { $_->name => $_->init_arg||$_->name }
|
||||
(
|
||||
(grep { $_->has_init_arg }
|
||||
$meta->attribute_metaclass->meta->get_all_attributes),
|
||||
grep { exists($_->{init_arg}) ? defined($_->init_arg) : 1 }
|
||||
map {
|
||||
my $meta = Moose::Util::resolve_metatrait_alias('Attribute', $_)
|
||||
->meta;
|
||||
map $meta->get_attribute($_), $meta->get_attribute_list
|
||||
} @{$spec{traits}||[]}
|
||||
)
|
||||
);
|
||||
# have to hard code this because Moose's role meta-model is lacking
|
||||
$spec_map{traits} ||= 'traits';
|
||||
|
||||
$spec{is} = 'ro' if $spec{is} eq 'lazy' or $spec{is} eq 'rwp';
|
||||
my $coerce = $spec{coerce};
|
||||
if (my $isa = $spec{isa}) {
|
||||
my $tc = $spec{isa} = do {
|
||||
if (my $mapped = $TYPE_MAP{$isa}) {
|
||||
my $type = $mapped->();
|
||||
unless ( Scalar::Util::blessed($type)
|
||||
&& $type->isa("Moose::Meta::TypeConstraint") ) {
|
||||
croak "error inflating attribute '$attr_name' for package '$name': "
|
||||
."\$TYPE_MAP{$isa} did not return a valid type constraint'";
|
||||
}
|
||||
$coerce ? $type->create_child_type(name => $type->name) : $type;
|
||||
} else {
|
||||
Moose::Meta::TypeConstraint->new(
|
||||
constraint => sub { eval { &$isa; 1 } }
|
||||
);
|
||||
}
|
||||
};
|
||||
if ($coerce) {
|
||||
$tc->coercion(Moose::Meta::TypeCoercion->new)
|
||||
->_compiled_type_coercion($coerce);
|
||||
$spec{coerce} = 1;
|
||||
}
|
||||
} elsif ($coerce) {
|
||||
my $attr = quotify($attr_name);
|
||||
my $tc = Moose::Meta::TypeConstraint->new(
|
||||
constraint => sub { die "This is not going to work" },
|
||||
inlined => sub {
|
||||
'my $r = $_[42]{'.$attr.'}; $_[42]{'.$attr.'} = 1; $r'
|
||||
},
|
||||
);
|
||||
$tc->coercion(Moose::Meta::TypeCoercion->new)
|
||||
->_compiled_type_coercion($coerce);
|
||||
$spec{isa} = $tc;
|
||||
$spec{coerce} = 1;
|
||||
}
|
||||
%spec =
|
||||
map { $spec_map{$_} => $spec{$_} }
|
||||
grep { exists $spec_map{$_} }
|
||||
keys %spec;
|
||||
push @attrs, $meta->add_attribute($attr_name => %spec);
|
||||
}
|
||||
foreach my $mouse (do { our %MOUSE; @{$MOUSE{$name}||[]} }) {
|
||||
foreach my $attr ($mouse->get_all_attributes) {
|
||||
my %spec = %{$attr};
|
||||
delete @spec{qw(
|
||||
associated_class associated_methods __METACLASS__
|
||||
provides curries
|
||||
)};
|
||||
my $attr_name = delete $spec{name};
|
||||
next if $seen_name{$attr_name}++;
|
||||
push @attrs, $meta->add_attribute($attr_name => %spec);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach my $meth_name (keys %methods) {
|
||||
my $meth_code = $methods{$meth_name};
|
||||
$meta->add_method($meth_name, $meth_code);
|
||||
}
|
||||
|
||||
if ($am_role) {
|
||||
my $info = $Moo::Role::INFO{$name};
|
||||
$meta->add_required_methods(@{$info->{requires}});
|
||||
foreach my $modifier (@{$info->{modifiers}}) {
|
||||
my ($type, @args) = @$modifier;
|
||||
my $code = pop @args;
|
||||
$meta->${\"add_${type}_method_modifier"}($_, $code) for @args;
|
||||
}
|
||||
}
|
||||
elsif ($am_class) {
|
||||
foreach my $attr (@attrs) {
|
||||
foreach my $method (@{$attr->associated_methods}) {
|
||||
$method->{body} = $name->can($method->name);
|
||||
}
|
||||
}
|
||||
bless(
|
||||
$meta->find_method_by_name('new'),
|
||||
'Moo::HandleMoose::FakeConstructor',
|
||||
);
|
||||
my $meta_meth;
|
||||
if (
|
||||
$meta_meth = $meta->find_method_by_name('meta')
|
||||
and $meta_meth->body == \&Moo::Object::meta
|
||||
) {
|
||||
bless($meta_meth, 'Moo::HandleMoose::FakeMeta');
|
||||
}
|
||||
# a combination of Moo and Moose may bypass a Moo constructor but still
|
||||
# use a Moo DEMOLISHALL. We need to make sure this is loaded before
|
||||
# global destruction.
|
||||
require Method::Generate::DemolishAll;
|
||||
}
|
||||
$meta->add_role(Class::MOP::class_of($_))
|
||||
for grep !/\|/ && $_ ne $name, # reject Foo|Bar and same-role-as-self
|
||||
keys %{$Moo::Role::APPLIED_TO{$name}}
|
||||
}
|
||||
$DID_INJECT{$name} = 1;
|
||||
$meta;
|
||||
}
|
||||
|
||||
1;
|
||||
41
database/perl/vendor/lib/Moo/HandleMoose/FakeMetaClass.pm
vendored
Normal file
41
database/perl/vendor/lib/Moo/HandleMoose/FakeMetaClass.pm
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
package Moo::HandleMoose::FakeMetaClass;
|
||||
use Moo::_strictures;
|
||||
use Carp ();
|
||||
BEGIN { our @CARP_NOT = qw(Moo::HandleMoose) }
|
||||
|
||||
sub DESTROY { }
|
||||
|
||||
sub AUTOLOAD {
|
||||
my ($meth) = (our $AUTOLOAD =~ /([^:]+)$/);
|
||||
my $self = shift;
|
||||
Carp::croak "Can't call $meth without object instance"
|
||||
if !ref $self;
|
||||
Carp::croak "Can't inflate Moose metaclass with Moo::sification disabled"
|
||||
if $Moo::sification::disabled;
|
||||
require Moo::HandleMoose;
|
||||
Moo::HandleMoose::inject_real_metaclass_for($self->{name})->$meth(@_)
|
||||
}
|
||||
sub can {
|
||||
my $self = shift;
|
||||
return $self->SUPER::can(@_)
|
||||
if !ref $self or $Moo::sification::disabled;
|
||||
require Moo::HandleMoose;
|
||||
Moo::HandleMoose::inject_real_metaclass_for($self->{name})->can(@_)
|
||||
}
|
||||
sub isa {
|
||||
my $self = shift;
|
||||
return $self->SUPER::isa(@_)
|
||||
if !ref $self or $Moo::sification::disabled;
|
||||
|
||||
# prevent inflation by Devel::StackTrace, which does this check. examining
|
||||
# the stack trace in an exception from inflation could re-trigger inflation
|
||||
# and cause another exception.
|
||||
return !!0
|
||||
if @_ == 1 && $_[0] eq 'Exception::Class::Base';
|
||||
|
||||
require Moo::HandleMoose;
|
||||
Moo::HandleMoose::inject_real_metaclass_for($self->{name})->isa(@_)
|
||||
}
|
||||
sub make_immutable { $_[0] }
|
||||
|
||||
1;
|
||||
89
database/perl/vendor/lib/Moo/HandleMoose/_TypeMap.pm
vendored
Normal file
89
database/perl/vendor/lib/Moo/HandleMoose/_TypeMap.pm
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
package Moo::HandleMoose::_TypeMap;
|
||||
use Moo::_strictures;
|
||||
|
||||
package
|
||||
Moo::HandleMoose;
|
||||
our %TYPE_MAP;
|
||||
|
||||
package Moo::HandleMoose::_TypeMap;
|
||||
|
||||
use Scalar::Util ();
|
||||
use Config ();
|
||||
|
||||
BEGIN {
|
||||
*_OVERLOAD_ON_REF = "$]" < 5.010000 ? sub(){1} : sub(){0};
|
||||
}
|
||||
|
||||
our %WEAK_TYPES;
|
||||
|
||||
sub _str_to_ref {
|
||||
my $in = shift;
|
||||
return $in
|
||||
if ref $in;
|
||||
|
||||
if ($in =~ /(?:^|=)([A-Z]+)\(0x([0-9a-zA-Z]+)\)$/) {
|
||||
my $type = $1;
|
||||
my $id = do { no warnings 'portable'; hex "$2" };
|
||||
require B;
|
||||
my $sv = bless \$id, 'B::SV';
|
||||
my $ref = eval { $sv->object_2svref };
|
||||
|
||||
if (!defined $ref or Scalar::Util::reftype($ref) ne $type) {
|
||||
die <<'END_ERROR';
|
||||
Moo initialization encountered types defined in a parent thread - ensure that
|
||||
Moo is require()d before any further thread spawns following a type definition.
|
||||
END_ERROR
|
||||
}
|
||||
|
||||
# on older perls where overloading magic is attached to the ref rather
|
||||
# than the ref target, reblessing will pick up the magic
|
||||
if (_OVERLOAD_ON_REF and my $class = Scalar::Util::blessed($ref)) {
|
||||
bless $ref, $class;
|
||||
}
|
||||
|
||||
return $ref;
|
||||
}
|
||||
return $in;
|
||||
}
|
||||
|
||||
sub TIEHASH { bless {}, $_[0] }
|
||||
|
||||
sub STORE {
|
||||
my ($self, $key, $value) = @_;
|
||||
my $type = _str_to_ref($key);
|
||||
$key = "$type";
|
||||
$WEAK_TYPES{$key} = $type;
|
||||
Scalar::Util::weaken($WEAK_TYPES{$key})
|
||||
if ref $type;
|
||||
$self->{$key} = $value;
|
||||
}
|
||||
|
||||
sub FETCH { $_[0]->{$_[1]} }
|
||||
sub FIRSTKEY { my $a = scalar keys %{$_[0]}; each %{$_[0]} }
|
||||
sub NEXTKEY { each %{$_[0]} }
|
||||
sub EXISTS { exists $_[0]->{$_[1]} }
|
||||
sub DELETE { delete $_[0]->{$_[1]} }
|
||||
sub CLEAR { %{$_[0]} = () }
|
||||
sub SCALAR { scalar %{$_[0]} }
|
||||
|
||||
sub CLONE {
|
||||
my @types = map {
|
||||
defined $WEAK_TYPES{$_} ? ($WEAK_TYPES{$_} => $TYPE_MAP{$_}) : ()
|
||||
} keys %TYPE_MAP;
|
||||
%WEAK_TYPES = ();
|
||||
%TYPE_MAP = @types;
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
my %types = %{$_[0]};
|
||||
untie %TYPE_MAP;
|
||||
%TYPE_MAP = %types;
|
||||
}
|
||||
|
||||
if ($Config::Config{useithreads}) {
|
||||
my @types = %TYPE_MAP;
|
||||
tie %TYPE_MAP, __PACKAGE__;
|
||||
%TYPE_MAP = @types;
|
||||
}
|
||||
|
||||
1;
|
||||
77
database/perl/vendor/lib/Moo/Object.pm
vendored
Normal file
77
database/perl/vendor/lib/Moo/Object.pm
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
package Moo::Object;
|
||||
|
||||
use Moo::_strictures;
|
||||
use Carp ();
|
||||
|
||||
our %NO_BUILD;
|
||||
our %NO_DEMOLISH;
|
||||
our $BUILD_MAKER;
|
||||
our $DEMOLISH_MAKER;
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
unless (exists $NO_DEMOLISH{$class}) {
|
||||
unless ($NO_DEMOLISH{$class} = !$class->can('DEMOLISH')) {
|
||||
($DEMOLISH_MAKER ||= do {
|
||||
require Method::Generate::DemolishAll;
|
||||
Method::Generate::DemolishAll->new
|
||||
})->generate_method($class);
|
||||
}
|
||||
}
|
||||
my $proto = $class->BUILDARGS(@_);
|
||||
$NO_BUILD{$class} and
|
||||
return bless({}, $class);
|
||||
$NO_BUILD{$class} = !$class->can('BUILD') unless exists $NO_BUILD{$class};
|
||||
$NO_BUILD{$class}
|
||||
? bless({}, $class)
|
||||
: bless({}, $class)->BUILDALL($proto);
|
||||
}
|
||||
|
||||
# Inlined into Method::Generate::Constructor::_generate_args() - keep in sync
|
||||
sub BUILDARGS {
|
||||
my $class = shift;
|
||||
scalar @_ == 1
|
||||
? ref $_[0] eq 'HASH'
|
||||
? { %{ $_[0] } }
|
||||
: Carp::croak("Single parameters to new() must be a HASH ref"
|
||||
. " data => ". $_[0])
|
||||
: @_ % 2
|
||||
? Carp::croak("The new() method for $class expects a hash reference or a"
|
||||
. " key/value list. You passed an odd number of arguments")
|
||||
: {@_}
|
||||
;
|
||||
}
|
||||
|
||||
sub BUILDALL {
|
||||
my $self = shift;
|
||||
$self->${\(($BUILD_MAKER ||= do {
|
||||
require Method::Generate::BuildAll;
|
||||
Method::Generate::BuildAll->new
|
||||
})->generate_method(ref($self)))}(@_);
|
||||
}
|
||||
|
||||
sub DEMOLISHALL {
|
||||
my $self = shift;
|
||||
$self->${\(($DEMOLISH_MAKER ||= do {
|
||||
require Method::Generate::DemolishAll;
|
||||
Method::Generate::DemolishAll->new
|
||||
})->generate_method(ref($self)))}(@_);
|
||||
}
|
||||
|
||||
sub does {
|
||||
return !!0
|
||||
unless ($INC{'Moose/Role.pm'} || $INC{'Role/Tiny.pm'});
|
||||
require Moo::Role;
|
||||
my $does = Moo::Role->can("does_role");
|
||||
{ no warnings 'redefine'; *does = $does }
|
||||
goto &$does;
|
||||
}
|
||||
|
||||
# duplicated in Moo::Role
|
||||
sub meta {
|
||||
require Moo::HandleMoose::FakeMetaClass;
|
||||
my $class = ref($_[0])||$_[0];
|
||||
bless({ name => $class }, 'Moo::HandleMoose::FakeMetaClass');
|
||||
}
|
||||
|
||||
1;
|
||||
574
database/perl/vendor/lib/Moo/Role.pm
vendored
Normal file
574
database/perl/vendor/lib/Moo/Role.pm
vendored
Normal file
@@ -0,0 +1,574 @@
|
||||
package Moo::Role;
|
||||
|
||||
use Moo::_strictures;
|
||||
use Moo::_Utils qw(
|
||||
_check_tracked
|
||||
_getglob
|
||||
_getstash
|
||||
_install_coderef
|
||||
_install_modifier
|
||||
_install_tracked
|
||||
_load_module
|
||||
_name_coderef
|
||||
_set_loaded
|
||||
_unimport_coderefs
|
||||
);
|
||||
use Carp qw(croak);
|
||||
use Role::Tiny ();
|
||||
BEGIN { our @ISA = qw(Role::Tiny) }
|
||||
BEGIN {
|
||||
our @CARP_NOT = qw(
|
||||
Method::Generate::Accessor
|
||||
Method::Generate::Constructor
|
||||
Moo::sification
|
||||
Moo::_Utils
|
||||
);
|
||||
}
|
||||
|
||||
our $VERSION = '2.004004';
|
||||
$VERSION =~ tr/_//d;
|
||||
|
||||
require Moo::sification;
|
||||
Moo::sification->import;
|
||||
|
||||
BEGIN {
|
||||
*INFO = \%Role::Tiny::INFO;
|
||||
*APPLIED_TO = \%Role::Tiny::APPLIED_TO;
|
||||
*COMPOSED = \%Role::Tiny::COMPOSED;
|
||||
*ON_ROLE_CREATE = \@Role::Tiny::ON_ROLE_CREATE;
|
||||
}
|
||||
|
||||
our %INFO;
|
||||
our %APPLIED_TO;
|
||||
our %APPLY_DEFAULTS;
|
||||
our %COMPOSED;
|
||||
our @ON_ROLE_CREATE;
|
||||
|
||||
sub import {
|
||||
my $target = caller;
|
||||
if ($Moo::MAKERS{$target} and $Moo::MAKERS{$target}{is_class}) {
|
||||
croak "Cannot import Moo::Role into a Moo class";
|
||||
}
|
||||
_set_loaded(caller);
|
||||
goto &Role::Tiny::import;
|
||||
}
|
||||
|
||||
sub _accessor_maker_for {
|
||||
my ($class, $target) = @_;
|
||||
($INFO{$target}{accessor_maker} ||= do {
|
||||
require Method::Generate::Accessor;
|
||||
Method::Generate::Accessor->new
|
||||
});
|
||||
}
|
||||
|
||||
sub _install_subs {
|
||||
my ($me, $target) = @_;
|
||||
my %install = $me->_gen_subs($target);
|
||||
_install_tracked $target => $_ => $install{$_}
|
||||
for sort keys %install;
|
||||
*{_getglob("${target}::meta")} = $me->can('meta');
|
||||
return;
|
||||
}
|
||||
|
||||
sub _gen_subs {
|
||||
my ($me, $target) = @_;
|
||||
return (
|
||||
has => sub {
|
||||
my $name_proto = shift;
|
||||
my @name_proto = ref $name_proto eq 'ARRAY' ? @$name_proto : $name_proto;
|
||||
if (@_ % 2 != 0) {
|
||||
croak("Invalid options for " . join(', ', map "'$_'", @name_proto)
|
||||
. " attribute(s): even number of arguments expected, got " . scalar @_)
|
||||
}
|
||||
my %spec = @_;
|
||||
foreach my $name (@name_proto) {
|
||||
my $spec_ref = @name_proto > 1 ? +{%spec} : \%spec;
|
||||
$me->_accessor_maker_for($target)
|
||||
->generate_method($target, $name, $spec_ref);
|
||||
push @{$INFO{$target}{attributes}||=[]}, $name, $spec_ref;
|
||||
$me->_maybe_reset_handlemoose($target);
|
||||
}
|
||||
},
|
||||
(map {
|
||||
my $type = $_;
|
||||
(
|
||||
$type => sub {
|
||||
push @{$INFO{$target}{modifiers}||=[]}, [ $type => @_ ];
|
||||
$me->_maybe_reset_handlemoose($target);
|
||||
},
|
||||
)
|
||||
} qw(before after around)),
|
||||
requires => sub {
|
||||
push @{$INFO{$target}{requires}||=[]}, @_;
|
||||
$me->_maybe_reset_handlemoose($target);
|
||||
},
|
||||
with => sub {
|
||||
$me->apply_roles_to_package($target, @_);
|
||||
$me->_maybe_reset_handlemoose($target);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
push @ON_ROLE_CREATE, sub {
|
||||
my $target = shift;
|
||||
if ($INC{'Moo/HandleMoose.pm'} && !$Moo::sification::disabled) {
|
||||
Moo::HandleMoose::inject_fake_metaclass_for($target);
|
||||
}
|
||||
};
|
||||
|
||||
# duplicate from Moo::Object
|
||||
sub meta {
|
||||
require Moo::HandleMoose::FakeMetaClass;
|
||||
my $class = ref($_[0])||$_[0];
|
||||
bless({ name => $class }, 'Moo::HandleMoose::FakeMetaClass');
|
||||
}
|
||||
|
||||
sub unimport {
|
||||
my $target = caller;
|
||||
_unimport_coderefs($target);
|
||||
}
|
||||
|
||||
sub _maybe_reset_handlemoose {
|
||||
my ($class, $target) = @_;
|
||||
if ($INC{'Moo/HandleMoose.pm'} && !$Moo::sification::disabled) {
|
||||
Moo::HandleMoose::maybe_reinject_fake_metaclass_for($target);
|
||||
}
|
||||
}
|
||||
|
||||
sub _non_methods {
|
||||
my $self = shift;
|
||||
my ($role) = @_;
|
||||
|
||||
my $non_methods = $self->SUPER::_non_methods(@_);
|
||||
|
||||
my $all_subs = $self->_all_subs($role);
|
||||
$non_methods->{$_} = $all_subs->{$_}
|
||||
for _check_tracked($role, [ keys %$all_subs ]);
|
||||
|
||||
return $non_methods;
|
||||
}
|
||||
|
||||
sub methods_provided_by {
|
||||
my ($self, $role) = @_;
|
||||
_load_module($role);
|
||||
$self->_inhale_if_moose($role);
|
||||
croak "${role} is not a Moo::Role" unless $self->is_role($role);
|
||||
return $self->SUPER::methods_provided_by($role);
|
||||
}
|
||||
|
||||
sub is_role {
|
||||
my ($self, $role) = @_;
|
||||
$self->_inhale_if_moose($role);
|
||||
$self->SUPER::is_role($role);
|
||||
}
|
||||
|
||||
sub _inhale_if_moose {
|
||||
my ($self, $role) = @_;
|
||||
my $meta;
|
||||
if (!$self->SUPER::is_role($role)
|
||||
and (
|
||||
$INC{"Moose.pm"}
|
||||
and $meta = Class::MOP::class_of($role)
|
||||
and ref $meta ne 'Moo::HandleMoose::FakeMetaClass'
|
||||
and $meta->isa('Moose::Meta::Role')
|
||||
)
|
||||
or (
|
||||
Mouse::Util->can('find_meta')
|
||||
and $meta = Mouse::Util::find_meta($role)
|
||||
and $meta->isa('Mouse::Meta::Role')
|
||||
)
|
||||
) {
|
||||
my $is_mouse = $meta->isa('Mouse::Meta::Role');
|
||||
$INFO{$role}{methods} = {
|
||||
map +($_ => $role->can($_)),
|
||||
grep $role->can($_),
|
||||
grep !($is_mouse && $_ eq 'meta'),
|
||||
grep !$meta->get_method($_)->isa('Class::MOP::Method::Meta'),
|
||||
$meta->get_method_list
|
||||
};
|
||||
$APPLIED_TO{$role} = {
|
||||
map +($_->name => 1), $meta->calculate_all_roles
|
||||
};
|
||||
$INFO{$role}{requires} = [ $meta->get_required_method_list ];
|
||||
$INFO{$role}{attributes} = [
|
||||
map +($_ => do {
|
||||
my $attr = $meta->get_attribute($_);
|
||||
my $spec = { %{ $is_mouse ? $attr : $attr->original_options } };
|
||||
|
||||
if ($spec->{isa}) {
|
||||
require Sub::Quote;
|
||||
|
||||
my $get_constraint = do {
|
||||
my $pkg = $is_mouse
|
||||
? 'Mouse::Util::TypeConstraints'
|
||||
: 'Moose::Util::TypeConstraints';
|
||||
_load_module($pkg);
|
||||
$pkg->can('find_or_create_isa_type_constraint');
|
||||
};
|
||||
|
||||
my $tc = $get_constraint->($spec->{isa});
|
||||
my $check = $tc->_compiled_type_constraint;
|
||||
my $tc_var = '$_check_for_'.Sub::Quote::sanitize_identifier($tc->name);
|
||||
|
||||
$spec->{isa} = Sub::Quote::quote_sub(
|
||||
qq{
|
||||
&${tc_var} or Carp::croak "Type constraint failed for \$_[0]"
|
||||
},
|
||||
{ $tc_var => \$check },
|
||||
{
|
||||
package => $role,
|
||||
},
|
||||
);
|
||||
|
||||
if ($spec->{coerce}) {
|
||||
|
||||
# Mouse has _compiled_type_coercion straight on the TC object
|
||||
$spec->{coerce} = $tc->${\(
|
||||
$tc->can('coercion')||sub { $_[0] }
|
||||
)}->_compiled_type_coercion;
|
||||
}
|
||||
}
|
||||
$spec;
|
||||
}), $meta->get_attribute_list
|
||||
];
|
||||
my $mods = $INFO{$role}{modifiers} = [];
|
||||
foreach my $type (qw(before after around)) {
|
||||
# Mouse pokes its own internals so we have to fall back to doing
|
||||
# the same thing in the absence of the Moose API method
|
||||
my $map = $meta->${\(
|
||||
$meta->can("get_${type}_method_modifiers_map")
|
||||
or sub { shift->{"${type}_method_modifiers"} }
|
||||
)};
|
||||
foreach my $method (keys %$map) {
|
||||
foreach my $mod (@{$map->{$method}}) {
|
||||
push @$mods, [ $type => $method => $mod ];
|
||||
}
|
||||
}
|
||||
}
|
||||
$INFO{$role}{inhaled_from_moose} = 1;
|
||||
$INFO{$role}{is_role} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub _maybe_make_accessors {
|
||||
my ($self, $target, $role) = @_;
|
||||
my $m;
|
||||
if ($INFO{$role} && $INFO{$role}{inhaled_from_moose}
|
||||
or $INC{"Moo.pm"}
|
||||
and $m = Moo->_accessor_maker_for($target)
|
||||
and ref($m) ne 'Method::Generate::Accessor') {
|
||||
$self->_make_accessors($target, $role);
|
||||
}
|
||||
}
|
||||
|
||||
sub _make_accessors_if_moose {
|
||||
my ($self, $target, $role) = @_;
|
||||
if ($INFO{$role} && $INFO{$role}{inhaled_from_moose}) {
|
||||
$self->_make_accessors($target, $role);
|
||||
}
|
||||
}
|
||||
|
||||
sub _make_accessors {
|
||||
my ($self, $target, $role) = @_;
|
||||
my $acc_gen = ($Moo::MAKERS{$target}{accessor} ||= do {
|
||||
require Method::Generate::Accessor;
|
||||
Method::Generate::Accessor->new
|
||||
});
|
||||
my $con_gen = $Moo::MAKERS{$target}{constructor};
|
||||
my @attrs = @{$INFO{$role}{attributes}||[]};
|
||||
while (my ($name, $spec) = splice @attrs, 0, 2) {
|
||||
# needed to ensure we got an index for an arrayref based generator
|
||||
if ($con_gen) {
|
||||
$spec = $con_gen->all_attribute_specs->{$name};
|
||||
}
|
||||
$acc_gen->generate_method($target, $name, $spec);
|
||||
}
|
||||
}
|
||||
|
||||
sub _undefer_subs {
|
||||
my ($self, $target, $role) = @_;
|
||||
if ($INC{'Sub/Defer.pm'}) {
|
||||
Sub::Defer::undefer_package($role);
|
||||
}
|
||||
}
|
||||
|
||||
sub role_application_steps {
|
||||
qw(_handle_constructor _undefer_subs _maybe_make_accessors),
|
||||
$_[0]->SUPER::role_application_steps;
|
||||
}
|
||||
|
||||
sub apply_roles_to_package {
|
||||
my ($me, $to, @roles) = @_;
|
||||
foreach my $role (@roles) {
|
||||
_load_module($role);
|
||||
$me->_inhale_if_moose($role);
|
||||
croak "${role} is not a Moo::Role" unless $me->is_role($role);
|
||||
}
|
||||
$me->SUPER::apply_roles_to_package($to, @roles);
|
||||
}
|
||||
|
||||
sub apply_single_role_to_package {
|
||||
my ($me, $to, $role) = @_;
|
||||
_load_module($role);
|
||||
$me->_inhale_if_moose($role);
|
||||
croak "${role} is not a Moo::Role" unless $me->is_role($role);
|
||||
$me->SUPER::apply_single_role_to_package($to, $role);
|
||||
}
|
||||
|
||||
sub create_class_with_roles {
|
||||
my ($me, $superclass, @roles) = @_;
|
||||
|
||||
my ($new_name, $compose_name) = $me->_composite_name($superclass, @roles);
|
||||
|
||||
return $new_name if $COMPOSED{class}{$new_name};
|
||||
|
||||
foreach my $role (@roles) {
|
||||
_load_module($role);
|
||||
$me->_inhale_if_moose($role);
|
||||
croak "${role} is not a Moo::Role" unless $me->is_role($role);
|
||||
}
|
||||
|
||||
my $m;
|
||||
if ($INC{"Moo.pm"}
|
||||
and $m = Moo->_accessor_maker_for($superclass)
|
||||
and ref($m) ne 'Method::Generate::Accessor') {
|
||||
# old fashioned way time.
|
||||
@{*{_getglob("${new_name}::ISA")}{ARRAY}} = ($superclass);
|
||||
$Moo::MAKERS{$new_name} = {is_class => 1};
|
||||
$me->apply_roles_to_package($new_name, @roles);
|
||||
}
|
||||
else {
|
||||
$me->SUPER::create_class_with_roles($superclass, @roles);
|
||||
$Moo::MAKERS{$new_name} = {is_class => 1};
|
||||
$me->_handle_constructor($new_name, $_) for @roles;
|
||||
}
|
||||
|
||||
if ($INC{'Moo/HandleMoose.pm'} && !$Moo::sification::disabled) {
|
||||
Moo::HandleMoose::inject_fake_metaclass_for($new_name);
|
||||
}
|
||||
$COMPOSED{class}{$new_name} = 1;
|
||||
_set_loaded($new_name, (caller)[1]);
|
||||
return $new_name;
|
||||
}
|
||||
|
||||
sub apply_roles_to_object {
|
||||
my ($me, $object, @roles) = @_;
|
||||
my $new = $me->SUPER::apply_roles_to_object($object, @roles);
|
||||
my $class = ref $new;
|
||||
_set_loaded($class, (caller)[1]);
|
||||
|
||||
my $apply_defaults = $APPLY_DEFAULTS{$class};
|
||||
if (!defined $apply_defaults) {
|
||||
my $attrs = { map @{$INFO{$_}{attributes}||[]}, @roles };
|
||||
|
||||
if ($INC{'Moo.pm'}
|
||||
and keys %$attrs
|
||||
and my $con_gen = Moo->_constructor_maker_for($class)
|
||||
and my $m = Moo->_accessor_maker_for($class)) {
|
||||
|
||||
my $specs = $con_gen->all_attribute_specs;
|
||||
|
||||
my %captures;
|
||||
my $code = join('',
|
||||
( map {
|
||||
my $name = $_;
|
||||
my $spec = $specs->{$name};
|
||||
if ($m->has_eager_default($name, $spec)) {
|
||||
my ($has, $has_cap)
|
||||
= $m->generate_simple_has('$_[0]', $name, $spec);
|
||||
my ($set, $pop_cap)
|
||||
= $m->generate_use_default('$_[0]', $name, $spec, $has);
|
||||
|
||||
@captures{keys %$has_cap, keys %$pop_cap}
|
||||
= (values %$has_cap, values %$pop_cap);
|
||||
"($set),";
|
||||
}
|
||||
else {
|
||||
();
|
||||
}
|
||||
} sort keys %$attrs ),
|
||||
);
|
||||
if ($code) {
|
||||
require Sub::Quote;
|
||||
$apply_defaults = Sub::Quote::quote_sub(
|
||||
"${class}::_apply_defaults",
|
||||
"no warnings 'void';\n$code",
|
||||
\%captures,
|
||||
{
|
||||
package => $class,
|
||||
no_install => 1,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
$APPLY_DEFAULTS{$class} = $apply_defaults ||= 0;
|
||||
}
|
||||
|
||||
if ($apply_defaults) {
|
||||
local $Carp::Internal{+__PACKAGE__} = 1;
|
||||
local $Carp::Internal{$class} = 1;
|
||||
$new->$apply_defaults;
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
|
||||
sub _composable_package_for {
|
||||
my ($self, $role) = @_;
|
||||
my $composed_name = 'Role::Tiny::_COMPOSABLE::'.$role;
|
||||
return $composed_name if $COMPOSED{role}{$composed_name};
|
||||
$self->_make_accessors_if_moose($composed_name, $role);
|
||||
$self->SUPER::_composable_package_for($role);
|
||||
}
|
||||
|
||||
sub _install_single_modifier {
|
||||
my ($me, @args) = @_;
|
||||
_install_modifier(@args);
|
||||
}
|
||||
|
||||
sub _install_does {
|
||||
my ($me, $to) = @_;
|
||||
|
||||
# If Role::Tiny actually installed the DOES, give it a name
|
||||
my $new = $me->SUPER::_install_does($to) or return;
|
||||
return _name_coderef("${to}::DOES", $new);
|
||||
}
|
||||
|
||||
sub does_role {
|
||||
my ($proto, $role) = @_;
|
||||
return 1
|
||||
if Role::Tiny::does_role($proto, $role);
|
||||
my $meta;
|
||||
if ($INC{'Moose.pm'}
|
||||
and $meta = Class::MOP::class_of($proto)
|
||||
and ref $meta ne 'Moo::HandleMoose::FakeMetaClass'
|
||||
and $meta->can('does_role')
|
||||
) {
|
||||
return $meta->does_role($role);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub _handle_constructor {
|
||||
my ($me, $to, $role) = @_;
|
||||
my $attr_info = $INFO{$role} && $INFO{$role}{attributes};
|
||||
return unless $attr_info && @$attr_info;
|
||||
my $info = $INFO{$to};
|
||||
my $con = $INC{"Moo.pm"} && Moo->_constructor_maker_for($to);
|
||||
my %existing
|
||||
= $info ? @{$info->{attributes} || []}
|
||||
: $con ? %{$con->all_attribute_specs || {}}
|
||||
: ();
|
||||
|
||||
my @attr_info =
|
||||
map { @{$attr_info}[$_, $_+1] }
|
||||
grep { ! $existing{$attr_info->[$_]} }
|
||||
map { 2 * $_ } 0..@$attr_info/2-1;
|
||||
|
||||
if ($info) {
|
||||
push @{$info->{attributes}||=[]}, @attr_info;
|
||||
}
|
||||
elsif ($con) {
|
||||
# shallow copy of the specs since the constructor will assign an index
|
||||
$con->register_attribute_specs(map ref() ? { %$_ } : $_, @attr_info);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Moo::Role - Minimal Object Orientation support for Roles
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
package My::Role;
|
||||
|
||||
use Moo::Role;
|
||||
use strictures 2;
|
||||
|
||||
sub foo { ... }
|
||||
|
||||
sub bar { ... }
|
||||
|
||||
has baz => (
|
||||
is => 'ro',
|
||||
);
|
||||
|
||||
1;
|
||||
|
||||
And elsewhere:
|
||||
|
||||
package Some::Class;
|
||||
|
||||
use Moo;
|
||||
use strictures 2;
|
||||
|
||||
# bar gets imported, but not foo
|
||||
with 'My::Role';
|
||||
|
||||
sub foo { ... }
|
||||
|
||||
1;
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
C<Moo::Role> builds upon L<Role::Tiny>, so look there for most of the
|
||||
documentation on how this works (in particular, using C<Moo::Role> also
|
||||
enables L<strict> and L<warnings>). The main addition here is extra bits to
|
||||
make the roles more "Moosey;" which is to say, it adds L</has>.
|
||||
|
||||
=head1 IMPORTED SUBROUTINES
|
||||
|
||||
See L<Role::Tiny/IMPORTED SUBROUTINES> for all the other subroutines that are
|
||||
imported by this module.
|
||||
|
||||
=head2 has
|
||||
|
||||
has attr => (
|
||||
is => 'ro',
|
||||
);
|
||||
|
||||
Declares an attribute for the class to be composed into. See
|
||||
L<Moo/has> for all options.
|
||||
|
||||
=head1 CLEANING UP IMPORTS
|
||||
|
||||
L<Moo::Role> cleans up its own imported methods and any imports
|
||||
declared before the C<use Moo::Role> statement automatically.
|
||||
Anything imported after C<use Moo::Role> will be composed into
|
||||
consuming packages. A package that consumes this role:
|
||||
|
||||
package My::Role::ID;
|
||||
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use Moo::Role;
|
||||
use Digest::SHA qw(sha1_hex);
|
||||
|
||||
requires 'name';
|
||||
|
||||
sub as_md5 { my ($self) = @_; return md5_hex($self->name); }
|
||||
sub as_sha1 { my ($self) = @_; return sha1_hex($self->name); }
|
||||
|
||||
1;
|
||||
|
||||
..will now have a C<< $self->sha1_hex() >> method available to it
|
||||
that probably does not do what you expect. On the other hand, a call
|
||||
to C<< $self->md5_hex() >> will die with the helpful error message:
|
||||
C<Can't locate object method "md5_hex">.
|
||||
|
||||
See L<Moo/"CLEANING UP IMPORTS"> for more details.
|
||||
|
||||
=head1 SUPPORT
|
||||
|
||||
See L<Moo> for support and contact information.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
See L<Moo> for authors.
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
See L<Moo> for the copyright and license.
|
||||
|
||||
=cut
|
||||
228
database/perl/vendor/lib/Moo/_Utils.pm
vendored
Normal file
228
database/perl/vendor/lib/Moo/_Utils.pm
vendored
Normal file
@@ -0,0 +1,228 @@
|
||||
package Moo::_Utils;
|
||||
use Moo::_strictures;
|
||||
|
||||
{
|
||||
no strict 'refs';
|
||||
sub _getglob { \*{$_[0]} }
|
||||
sub _getstash { \%{"$_[0]::"} }
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
my ($su, $sn);
|
||||
$su = $INC{'Sub/Util.pm'} && defined &Sub::Util::set_subname
|
||||
or $sn = $INC{'Sub/Name.pm'}
|
||||
or $su = eval { require Sub::Util; } && defined &Sub::Util::set_subname
|
||||
or $sn = eval { require Sub::Name; };
|
||||
|
||||
*_subname = $su ? \&Sub::Util::set_subname
|
||||
: $sn ? \&Sub::Name::subname
|
||||
: sub { $_[1] };
|
||||
*_CAN_SUBNAME = ($su || $sn) ? sub(){1} : sub(){0};
|
||||
|
||||
*_WORK_AROUND_BROKEN_MODULE_STATE = "$]" < 5.009 ? sub(){1} : sub(){0};
|
||||
*_WORK_AROUND_HINT_LEAKAGE
|
||||
= "$]" < 5.011 && !("$]" >= 5.009004 && "$]" < 5.010001)
|
||||
? sub(){1} : sub(){0};
|
||||
|
||||
my $module_name_rx = qr/\A(?!\d)\w+(?:::\w+)*\z/;
|
||||
*_module_name_rx = sub(){$module_name_rx};
|
||||
}
|
||||
|
||||
use Exporter qw(import);
|
||||
use Config;
|
||||
use Scalar::Util qw(weaken);
|
||||
use Carp qw(croak);
|
||||
|
||||
# this should be empty, but some CPAN modules expect these
|
||||
our @EXPORT = qw(
|
||||
_install_coderef
|
||||
_load_module
|
||||
);
|
||||
|
||||
our @EXPORT_OK = qw(
|
||||
_check_tracked
|
||||
_getglob
|
||||
_getstash
|
||||
_install_coderef
|
||||
_install_modifier
|
||||
_install_tracked
|
||||
_load_module
|
||||
_maybe_load_module
|
||||
_module_name_rx
|
||||
_name_coderef
|
||||
_set_loaded
|
||||
_unimport_coderefs
|
||||
);
|
||||
|
||||
my %EXPORTS;
|
||||
|
||||
sub _install_modifier {
|
||||
my $target = $_[0];
|
||||
my $type = $_[1];
|
||||
my $code = $_[-1];
|
||||
my @names = @_[2 .. $#_ - 1];
|
||||
|
||||
@names = @{ $names[0] }
|
||||
if ref($names[0]) eq 'ARRAY';
|
||||
|
||||
my @tracked = _check_tracked($target, \@names);
|
||||
|
||||
if ($INC{'Sub/Defer.pm'}) {
|
||||
for my $name (@names) {
|
||||
# CMM will throw for us if it doesn't exist
|
||||
if (my $to_modify = $target->can($name)) {
|
||||
Sub::Defer::undefer_sub($to_modify);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
require Class::Method::Modifiers;
|
||||
Class::Method::Modifiers::install_modifier(@_);
|
||||
|
||||
if (@tracked) {
|
||||
my $exports = $EXPORTS{$target};
|
||||
weaken($exports->{$_} = $target->can($_))
|
||||
for @tracked;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub _install_tracked {
|
||||
my ($target, $name, $code) = @_;
|
||||
my $from = caller;
|
||||
weaken($EXPORTS{$target}{$name} = $code);
|
||||
_install_coderef("${target}::${name}", "${from}::${name}", $code);
|
||||
}
|
||||
|
||||
sub Moo::_Util::__GUARD__::DESTROY {
|
||||
delete $INC{$_[0]->[0]} if @{$_[0]};
|
||||
}
|
||||
|
||||
sub _require {
|
||||
my ($file) = @_;
|
||||
my $guard = _WORK_AROUND_BROKEN_MODULE_STATE
|
||||
&& bless([ $file ], 'Moo::_Util::__GUARD__');
|
||||
local %^H if _WORK_AROUND_HINT_LEAKAGE;
|
||||
if (!eval { require $file; 1 }) {
|
||||
my $e = $@ || "Can't locate $file";
|
||||
my $me = __FILE__;
|
||||
$e =~ s{ at \Q$me\E line \d+\.\n\z}{};
|
||||
return $e;
|
||||
}
|
||||
pop @$guard if _WORK_AROUND_BROKEN_MODULE_STATE;
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub _load_module {
|
||||
my ($module) = @_;
|
||||
croak qq{"$module" is not a module name!}
|
||||
unless $module =~ _module_name_rx;
|
||||
(my $file = "$module.pm") =~ s{::}{/}g;
|
||||
return 1
|
||||
if $INC{$file};
|
||||
|
||||
my $e = _require $file;
|
||||
return 1
|
||||
if !defined $e;
|
||||
|
||||
croak $e
|
||||
if $e !~ /\ACan't locate \Q$file\E /;
|
||||
|
||||
# can't just ->can('can') because a sub-package Foo::Bar::Baz
|
||||
# creates a 'Baz::' key in Foo::Bar's symbol table
|
||||
my $stash = _getstash($module)||{};
|
||||
no strict 'refs';
|
||||
return 1 if grep +exists &{"${module}::$_"}, grep !/::\z/, keys %$stash;
|
||||
return 1
|
||||
if $INC{"Moose.pm"} && Class::MOP::class_of($module)
|
||||
or Mouse::Util->can('find_meta') && Mouse::Util::find_meta($module);
|
||||
|
||||
croak $e;
|
||||
}
|
||||
|
||||
our %MAYBE_LOADED;
|
||||
sub _maybe_load_module {
|
||||
my $module = $_[0];
|
||||
return $MAYBE_LOADED{$module}
|
||||
if exists $MAYBE_LOADED{$module};
|
||||
(my $file = "$module.pm") =~ s{::}{/}g;
|
||||
|
||||
my $e = _require $file;
|
||||
if (!defined $e) {
|
||||
return $MAYBE_LOADED{$module} = 1;
|
||||
}
|
||||
elsif ($e !~ /\ACan't locate \Q$file\E /) {
|
||||
warn "$module exists but failed to load with error: $e";
|
||||
}
|
||||
return $MAYBE_LOADED{$module} = 0;
|
||||
}
|
||||
|
||||
sub _set_loaded {
|
||||
(my $file = "$_[0].pm") =~ s{::}{/}g;
|
||||
$INC{$file} ||= $_[1];
|
||||
}
|
||||
|
||||
sub _install_coderef {
|
||||
my ($glob, $code) = (_getglob($_[0]), _name_coderef(@_));
|
||||
no warnings 'redefine';
|
||||
if (*{$glob}{CODE}) {
|
||||
*{$glob} = $code;
|
||||
}
|
||||
# perl will sometimes warn about mismatched prototypes coming from the
|
||||
# inheritance cache, so disable them if we aren't redefining a sub
|
||||
else {
|
||||
no warnings 'prototype';
|
||||
*{$glob} = $code;
|
||||
}
|
||||
}
|
||||
|
||||
sub _name_coderef {
|
||||
shift if @_ > 2; # three args is (target, name, sub)
|
||||
_CAN_SUBNAME ? _subname(@_) : $_[1];
|
||||
}
|
||||
|
||||
sub _check_tracked {
|
||||
my ($target, $names) = @_;
|
||||
my $stash = _getstash($target);
|
||||
my $exports = $EXPORTS{$target}
|
||||
or return;
|
||||
|
||||
$names = [keys %$exports]
|
||||
if !$names;
|
||||
my %rev =
|
||||
map +($exports->{$_} => $_),
|
||||
grep defined $exports->{$_},
|
||||
keys %$exports;
|
||||
|
||||
return
|
||||
grep {
|
||||
my $g = $stash->{$_};
|
||||
$g && defined &$g && exists $rev{\&$g};
|
||||
}
|
||||
@$names;
|
||||
}
|
||||
|
||||
sub _unimport_coderefs {
|
||||
my ($target) = @_;
|
||||
|
||||
my $stash = _getstash($target);
|
||||
my @exports = _check_tracked($target);
|
||||
|
||||
foreach my $name (@exports) {
|
||||
my $old = delete $stash->{$name};
|
||||
my $full_name = join('::',$target,$name);
|
||||
# Copy everything except the code slot back into place (e.g. $has)
|
||||
foreach my $type (qw(SCALAR HASH ARRAY IO)) {
|
||||
next unless defined(*{$old}{$type});
|
||||
no strict 'refs';
|
||||
*$full_name = *{$old}{$type};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($Config{useithreads}) {
|
||||
require Moo::HandleMoose::_TypeMap;
|
||||
}
|
||||
|
||||
1;
|
||||
10
database/perl/vendor/lib/Moo/_mro.pm
vendored
Normal file
10
database/perl/vendor/lib/Moo/_mro.pm
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
package Moo::_mro;
|
||||
use Moo::_strictures;
|
||||
|
||||
if ("$]" >= 5.010_000) {
|
||||
require mro;
|
||||
} else {
|
||||
require MRO::Compat;
|
||||
}
|
||||
|
||||
1;
|
||||
19
database/perl/vendor/lib/Moo/_strictures.pm
vendored
Normal file
19
database/perl/vendor/lib/Moo/_strictures.pm
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
package Moo::_strictures;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub import {
|
||||
if ($ENV{MOO_FATAL_WARNINGS}) {
|
||||
require strictures;
|
||||
strictures->VERSION(2);
|
||||
@_ = ('strictures');
|
||||
goto &strictures::import;
|
||||
}
|
||||
else {
|
||||
strict->import;
|
||||
warnings->import;
|
||||
warnings->unimport('once');
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
42
database/perl/vendor/lib/Moo/sification.pm
vendored
Normal file
42
database/perl/vendor/lib/Moo/sification.pm
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
package Moo::sification;
|
||||
|
||||
use Moo::_strictures;
|
||||
no warnings 'once';
|
||||
BEGIN {
|
||||
*_USE_DGD = "$]" < 5.014 ? sub(){1} : sub(){0};
|
||||
require Devel::GlobalDestruction
|
||||
if _USE_DGD();
|
||||
}
|
||||
use Carp qw(croak);
|
||||
BEGIN { our @CARP_NOT = qw(Moo::HandleMoose) }
|
||||
|
||||
sub unimport {
|
||||
croak "Can't disable Moo::sification after inflation has been done"
|
||||
if $Moo::HandleMoose::SETUP_DONE;
|
||||
our $disabled = 1;
|
||||
}
|
||||
|
||||
sub Moo::HandleMoose::AuthorityHack::DESTROY {
|
||||
unless (our $disabled or
|
||||
_USE_DGD
|
||||
? Devel::GlobalDestruction::in_global_destruction()
|
||||
: ${^GLOBAL_PHASE} eq 'DESTRUCT'
|
||||
) {
|
||||
require Moo::HandleMoose;
|
||||
Moo::HandleMoose->import;
|
||||
}
|
||||
}
|
||||
|
||||
sub import {
|
||||
return
|
||||
if our $setup_done;
|
||||
if ($INC{"Moose.pm"}) {
|
||||
require Moo::HandleMoose;
|
||||
Moo::HandleMoose->import;
|
||||
} else {
|
||||
$Moose::AUTHORITY = bless({}, 'Moo::HandleMoose::AuthorityHack');
|
||||
}
|
||||
$setup_done = 1;
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user