Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View 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;

View 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;