Initial Commit
This commit is contained in:
125
database/perl/vendor/lib/Class/MOP/Mixin/AttributeCore.pm
vendored
Normal file
125
database/perl/vendor/lib/Class/MOP/Mixin/AttributeCore.pm
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
package Class::MOP::Mixin::AttributeCore;
|
||||
our $VERSION = '2.2014';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Scalar::Util 'blessed';
|
||||
|
||||
use parent 'Class::MOP::Mixin';
|
||||
|
||||
sub has_accessor { defined $_[0]->{'accessor'} }
|
||||
sub has_reader { defined $_[0]->{'reader'} }
|
||||
sub has_writer { defined $_[0]->{'writer'} }
|
||||
sub has_predicate { defined $_[0]->{'predicate'} }
|
||||
sub has_clearer { defined $_[0]->{'clearer'} }
|
||||
sub has_builder { defined $_[0]->{'builder'} }
|
||||
sub has_init_arg { defined $_[0]->{'init_arg'} }
|
||||
sub has_default { exists $_[0]->{'default'} }
|
||||
sub has_initializer { defined $_[0]->{'initializer'} }
|
||||
sub has_insertion_order { defined $_[0]->{'insertion_order'} }
|
||||
|
||||
sub _set_insertion_order { $_[0]->{'insertion_order'} = $_[1] }
|
||||
|
||||
sub has_read_method { $_[0]->has_reader || $_[0]->has_accessor }
|
||||
sub has_write_method { $_[0]->has_writer || $_[0]->has_accessor }
|
||||
|
||||
sub is_default_a_coderef {
|
||||
# Uber hack because it is called from CMOP::Attribute constructor as
|
||||
# $class->is_default_a_coderef(\%options)
|
||||
my ($value) = ref $_[0] ? $_[0]->{'default'} : $_[1]->{'default'};
|
||||
|
||||
return unless ref($value);
|
||||
|
||||
return ref($value) eq 'CODE'
|
||||
|| ( blessed($value) && $value->isa('Class::MOP::Method') );
|
||||
}
|
||||
|
||||
sub default {
|
||||
my ( $self, $instance ) = @_;
|
||||
if ( defined $instance && $self->is_default_a_coderef ) {
|
||||
# if the default is a CODE ref, then we pass in the instance and
|
||||
# default can return a value based on that instance. Somewhat crude,
|
||||
# but works.
|
||||
return $self->{'default'}->($instance);
|
||||
}
|
||||
$self->{'default'};
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# ABSTRACT: Core attributes shared by attribute metaclasses
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=encoding UTF-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Class::MOP::Mixin::AttributeCore - Core attributes shared by attribute metaclasses
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
version 2.2014
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This class implements the core attributes (aka properties) shared by all
|
||||
attributes. See the L<Class::MOP::Attribute> documentation for API details.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Stevan Little <stevan@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Dave Rolsky <autarch@urth.org>
|
||||
|
||||
=item *
|
||||
|
||||
Jesse Luehrs <doy@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Shawn M Moore <sartak@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
|
||||
|
||||
=item *
|
||||
|
||||
Karen Etheridge <ether@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Florian Ragwitz <rafl@debian.org>
|
||||
|
||||
=item *
|
||||
|
||||
Hans Dieter Pearcey <hdp@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Chris Prather <chris@prather.org>
|
||||
|
||||
=item *
|
||||
|
||||
Matt S Trout <mstrout@cpan.org>
|
||||
|
||||
=back
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
This software is copyright (c) 2006 by Infinity Interactive, Inc.
|
||||
|
||||
This is free software; you can redistribute it and/or modify it under
|
||||
the same terms as the Perl 5 programming language system itself.
|
||||
|
||||
=cut
|
||||
171
database/perl/vendor/lib/Class/MOP/Mixin/HasAttributes.pm
vendored
Normal file
171
database/perl/vendor/lib/Class/MOP/Mixin/HasAttributes.pm
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
package Class::MOP::Mixin::HasAttributes;
|
||||
our $VERSION = '2.2014';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Scalar::Util 'blessed';
|
||||
|
||||
use parent 'Class::MOP::Mixin';
|
||||
|
||||
sub add_attribute {
|
||||
my $self = shift;
|
||||
|
||||
my $attribute
|
||||
= blessed( $_[0] ) ? $_[0] : $self->attribute_metaclass->new(@_);
|
||||
|
||||
( $attribute->isa('Class::MOP::Mixin::AttributeCore') )
|
||||
|| $self->_throw_exception( AttributeMustBeAnClassMOPMixinAttributeCoreOrSubclass => attribute => $attribute,
|
||||
class_name => $self->name,
|
||||
);
|
||||
|
||||
$self->_attach_attribute($attribute);
|
||||
|
||||
my $attr_name = $attribute->name;
|
||||
|
||||
$self->remove_attribute($attr_name)
|
||||
if $self->has_attribute($attr_name);
|
||||
|
||||
my $order = ( scalar keys %{ $self->_attribute_map } );
|
||||
$attribute->_set_insertion_order($order);
|
||||
|
||||
$self->_attribute_map->{$attr_name} = $attribute;
|
||||
|
||||
# This method is called to allow for installing accessors. Ideally, we'd
|
||||
# use method overriding, but then the subclass would be responsible for
|
||||
# making the attribute, which would end up with lots of code
|
||||
# duplication. Even more ideally, we'd use augment/inner, but this is
|
||||
# Class::MOP!
|
||||
$self->_post_add_attribute($attribute)
|
||||
if $self->can('_post_add_attribute');
|
||||
|
||||
return $attribute;
|
||||
}
|
||||
|
||||
sub has_attribute {
|
||||
my ( $self, $attribute_name ) = @_;
|
||||
|
||||
( defined $attribute_name )
|
||||
|| $self->_throw_exception( MustDefineAnAttributeName => class_name => $self->name );
|
||||
|
||||
exists $self->_attribute_map->{$attribute_name};
|
||||
}
|
||||
|
||||
sub get_attribute {
|
||||
my ( $self, $attribute_name ) = @_;
|
||||
|
||||
( defined $attribute_name )
|
||||
|| $self->_throw_exception( MustDefineAnAttributeName => class_name => $self->name );
|
||||
|
||||
return $self->_attribute_map->{$attribute_name};
|
||||
}
|
||||
|
||||
sub remove_attribute {
|
||||
my ( $self, $attribute_name ) = @_;
|
||||
|
||||
( defined $attribute_name )
|
||||
|| $self->_throw_exception( MustDefineAnAttributeName => class_name => $self->name );
|
||||
|
||||
my $removed_attribute = $self->_attribute_map->{$attribute_name};
|
||||
return unless defined $removed_attribute;
|
||||
|
||||
delete $self->_attribute_map->{$attribute_name};
|
||||
|
||||
return $removed_attribute;
|
||||
}
|
||||
|
||||
sub get_attribute_list {
|
||||
my $self = shift;
|
||||
keys %{ $self->_attribute_map };
|
||||
}
|
||||
|
||||
sub _restore_metaattributes_from {
|
||||
my $self = shift;
|
||||
my ($old_meta) = @_;
|
||||
|
||||
for my $attr (sort { $a->insertion_order <=> $b->insertion_order }
|
||||
map { $old_meta->get_attribute($_) }
|
||||
$old_meta->get_attribute_list) {
|
||||
$attr->_make_compatible_with($self->attribute_metaclass);
|
||||
$self->add_attribute($attr);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# ABSTRACT: Methods for metaclasses which have attributes
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=encoding UTF-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Class::MOP::Mixin::HasAttributes - Methods for metaclasses which have attributes
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
version 2.2014
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This class implements methods for metaclasses which have attributes
|
||||
(L<Class::MOP::Class> and L<Moose::Meta::Role>). See L<Class::MOP::Class> for
|
||||
API details.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Stevan Little <stevan@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Dave Rolsky <autarch@urth.org>
|
||||
|
||||
=item *
|
||||
|
||||
Jesse Luehrs <doy@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Shawn M Moore <sartak@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
|
||||
|
||||
=item *
|
||||
|
||||
Karen Etheridge <ether@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Florian Ragwitz <rafl@debian.org>
|
||||
|
||||
=item *
|
||||
|
||||
Hans Dieter Pearcey <hdp@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Chris Prather <chris@prather.org>
|
||||
|
||||
=item *
|
||||
|
||||
Matt S Trout <mstrout@cpan.org>
|
||||
|
||||
=back
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
This software is copyright (c) 2006 by Infinity Interactive, Inc.
|
||||
|
||||
This is free software; you can redistribute it and/or modify it under
|
||||
the same terms as the Perl 5 programming language system itself.
|
||||
|
||||
=cut
|
||||
304
database/perl/vendor/lib/Class/MOP/Mixin/HasMethods.pm
vendored
Normal file
304
database/perl/vendor/lib/Class/MOP/Mixin/HasMethods.pm
vendored
Normal file
@@ -0,0 +1,304 @@
|
||||
package Class::MOP::Mixin::HasMethods;
|
||||
our $VERSION = '2.2014';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Class::MOP::Method::Meta;
|
||||
|
||||
use Scalar::Util 'blessed', 'reftype';
|
||||
use Sub::Name 'subname';
|
||||
|
||||
use parent 'Class::MOP::Mixin';
|
||||
|
||||
sub _meta_method_class { 'Class::MOP::Method::Meta' }
|
||||
|
||||
sub _add_meta_method {
|
||||
my $self = shift;
|
||||
my ($name) = @_;
|
||||
my $existing_method = $self->can('find_method_by_name')
|
||||
? $self->find_method_by_name($name)
|
||||
: $self->get_method($name);
|
||||
return if $existing_method
|
||||
&& $existing_method->isa($self->_meta_method_class);
|
||||
$self->add_method(
|
||||
$name => $self->_meta_method_class->wrap(
|
||||
name => $name,
|
||||
package_name => $self->name,
|
||||
associated_metaclass => $self,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
sub wrap_method_body {
|
||||
my ( $self, %args ) = @_;
|
||||
|
||||
( $args{body} && 'CODE' eq reftype $args{body} )
|
||||
|| $self->_throw_exception( CodeBlockMustBeACodeRef => instance => $self,
|
||||
params => \%args
|
||||
);
|
||||
$self->method_metaclass->wrap(
|
||||
package_name => $self->name,
|
||||
%args,
|
||||
);
|
||||
}
|
||||
|
||||
sub add_method {
|
||||
my ( $self, $method_name, $method ) = @_;
|
||||
( defined $method_name && length $method_name )
|
||||
|| $self->_throw_exception( MustDefineAMethodName => instance => $self );
|
||||
|
||||
my $package_name = $self->name;
|
||||
|
||||
my $body;
|
||||
if ( blessed($method) && $method->isa('Class::MOP::Method') ) {
|
||||
$body = $method->body;
|
||||
if ( $method->package_name ne $package_name ) {
|
||||
$method = $method->clone(
|
||||
package_name => $package_name,
|
||||
name => $method_name,
|
||||
);
|
||||
}
|
||||
|
||||
$method->attach_to_class($self);
|
||||
}
|
||||
else {
|
||||
# If a raw code reference is supplied, its method object is not created.
|
||||
# The method object won't be created until required.
|
||||
$body = $method;
|
||||
}
|
||||
|
||||
$self->_method_map->{$method_name} = $method;
|
||||
|
||||
my ($current_package, $current_name) = Class::MOP::get_code_info($body);
|
||||
|
||||
subname($package_name . '::' . $method_name, $body)
|
||||
unless defined $current_name && $current_name !~ /^__ANON__/;
|
||||
|
||||
$self->add_package_symbol("&$method_name", $body);
|
||||
|
||||
# we added the method to the method map too, so it's still valid
|
||||
$self->update_package_cache_flag;
|
||||
}
|
||||
|
||||
sub _code_is_mine {
|
||||
my ( $self, $code ) = @_;
|
||||
|
||||
my ( $code_package, $code_name ) = Class::MOP::get_code_info($code);
|
||||
|
||||
return ( $code_package && $code_package eq $self->name )
|
||||
|| ( $code_package eq 'constant' && $code_name eq '__ANON__' );
|
||||
}
|
||||
|
||||
sub has_method {
|
||||
my ( $self, $method_name ) = @_;
|
||||
|
||||
( defined $method_name && length $method_name )
|
||||
|| $self->_throw_exception( MustDefineAMethodName => instance => $self );
|
||||
|
||||
my $method = $self->_get_maybe_raw_method($method_name);
|
||||
return if not $method;
|
||||
|
||||
return defined($self->_method_map->{$method_name} = $method);
|
||||
}
|
||||
|
||||
sub get_method {
|
||||
my ( $self, $method_name ) = @_;
|
||||
|
||||
( defined $method_name && length $method_name )
|
||||
|| $self->_throw_exception( MustDefineAMethodName => instance => $self );
|
||||
|
||||
my $method = $self->_get_maybe_raw_method($method_name);
|
||||
return if not $method;
|
||||
|
||||
return $method if blessed($method) && $method->isa('Class::MOP::Method');
|
||||
|
||||
return $self->_method_map->{$method_name} = $self->wrap_method_body(
|
||||
body => $method,
|
||||
name => $method_name,
|
||||
associated_metaclass => $self,
|
||||
);
|
||||
}
|
||||
|
||||
sub _get_maybe_raw_method {
|
||||
my ( $self, $method_name ) = @_;
|
||||
|
||||
my $map_entry = $self->_method_map->{$method_name};
|
||||
return $map_entry if defined $map_entry;
|
||||
|
||||
my $code = $self->get_package_symbol("&$method_name");
|
||||
|
||||
return unless $code && $self->_code_is_mine($code);
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
sub remove_method {
|
||||
my ( $self, $method_name ) = @_;
|
||||
|
||||
( defined $method_name && length $method_name )
|
||||
|| $self->_throw_exception( MustDefineAMethodName => instance => $self );
|
||||
|
||||
my $removed_method = delete $self->_method_map->{$method_name};
|
||||
|
||||
$self->remove_package_symbol("&$method_name");
|
||||
|
||||
$removed_method->detach_from_class
|
||||
if blessed($removed_method) && $removed_method->isa('Class::MOP::Method');
|
||||
|
||||
# still valid, since we just removed the method from the map
|
||||
$self->update_package_cache_flag;
|
||||
|
||||
return $removed_method;
|
||||
}
|
||||
|
||||
sub get_method_list {
|
||||
my $self = shift;
|
||||
|
||||
return keys %{ $self->_full_method_map };
|
||||
}
|
||||
|
||||
sub _get_local_methods {
|
||||
my $self = shift;
|
||||
|
||||
return values %{ $self->_full_method_map };
|
||||
}
|
||||
|
||||
sub _restore_metamethods_from {
|
||||
my $self = shift;
|
||||
my ($old_meta) = @_;
|
||||
|
||||
my $package_name = $self->name;
|
||||
|
||||
# Check if Perl debugger is enabled
|
||||
my $debugger_enabled = ($^P & 0x10);
|
||||
my $debug_method_info;
|
||||
|
||||
for my $method ($old_meta->_get_local_methods) {
|
||||
my $method_name = $method->name;
|
||||
|
||||
# Track DB::sub information for this method if debugger is enabled.
|
||||
# This contains original method filename and line numbers.
|
||||
$debug_method_info = '';
|
||||
if ($debugger_enabled) {
|
||||
$debug_method_info = $DB::sub{$package_name . "::" . $method_name}
|
||||
}
|
||||
|
||||
$method->_make_compatible_with($self->method_metaclass);
|
||||
$self->add_method($method_name => $method);
|
||||
|
||||
# Restore method debug information, which can be clobbered by add_method.
|
||||
# Note that we handle this here instead of in add_method, because we
|
||||
# only want to preserve the original debug info in cases where we are
|
||||
# restoring a method, not overwriting a method.
|
||||
if ($debugger_enabled && $debug_method_info) {
|
||||
$DB::sub{$package_name . "::" . $method_name} = $debug_method_info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub reset_package_cache_flag { (shift)->{'_package_cache_flag'} = undef }
|
||||
sub update_package_cache_flag {
|
||||
my $self = shift;
|
||||
# NOTE:
|
||||
# we can manually update the cache number
|
||||
# since we are actually adding the method
|
||||
# to our cache as well. This avoids us
|
||||
# having to regenerate the method_map.
|
||||
# - SL
|
||||
$self->{'_package_cache_flag'} = Class::MOP::check_package_cache_flag($self->name);
|
||||
}
|
||||
|
||||
sub _full_method_map {
|
||||
my $self = shift;
|
||||
|
||||
my $pkg_gen = Class::MOP::check_package_cache_flag($self->name);
|
||||
|
||||
if (($self->{_package_cache_flag_full} || -1) != $pkg_gen) {
|
||||
# forcibly reify all method map entries
|
||||
$self->get_method($_)
|
||||
for $self->list_all_package_symbols('CODE');
|
||||
$self->{_package_cache_flag_full} = $pkg_gen;
|
||||
}
|
||||
|
||||
return $self->_method_map;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# ABSTRACT: Methods for metaclasses which have methods
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=encoding UTF-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Class::MOP::Mixin::HasMethods - Methods for metaclasses which have methods
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
version 2.2014
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This class implements methods for metaclasses which have methods
|
||||
(L<Class::MOP::Class> and L<Moose::Meta::Role>). See L<Class::MOP::Class> for
|
||||
API details.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Stevan Little <stevan@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Dave Rolsky <autarch@urth.org>
|
||||
|
||||
=item *
|
||||
|
||||
Jesse Luehrs <doy@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Shawn M Moore <sartak@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
|
||||
|
||||
=item *
|
||||
|
||||
Karen Etheridge <ether@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Florian Ragwitz <rafl@debian.org>
|
||||
|
||||
=item *
|
||||
|
||||
Hans Dieter Pearcey <hdp@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Chris Prather <chris@prather.org>
|
||||
|
||||
=item *
|
||||
|
||||
Matt S Trout <mstrout@cpan.org>
|
||||
|
||||
=back
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
This software is copyright (c) 2006 by Infinity Interactive, Inc.
|
||||
|
||||
This is free software; you can redistribute it and/or modify it under
|
||||
the same terms as the Perl 5 programming language system itself.
|
||||
|
||||
=cut
|
||||
243
database/perl/vendor/lib/Class/MOP/Mixin/HasOverloads.pm
vendored
Normal file
243
database/perl/vendor/lib/Class/MOP/Mixin/HasOverloads.pm
vendored
Normal file
@@ -0,0 +1,243 @@
|
||||
package Class::MOP::Mixin::HasOverloads;
|
||||
our $VERSION = '2.2014';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Class::MOP::Overload;
|
||||
|
||||
use Devel::OverloadInfo 0.005 'overload_info', 'overload_op_info';
|
||||
use Scalar::Util 'blessed';
|
||||
|
||||
use overload ();
|
||||
|
||||
use parent 'Class::MOP::Mixin';
|
||||
|
||||
sub is_overloaded {
|
||||
my $self = shift;
|
||||
Devel::OverloadInfo::is_overloaded($self->name);
|
||||
}
|
||||
|
||||
sub get_overload_list {
|
||||
my $self = shift;
|
||||
|
||||
my $info = $self->_overload_info;
|
||||
return grep { $_ ne 'fallback' } keys %{$info}
|
||||
}
|
||||
|
||||
sub get_all_overloaded_operators {
|
||||
my $self = shift;
|
||||
return map { $self->_overload_for($_) } $self->get_overload_list;
|
||||
}
|
||||
|
||||
sub has_overloaded_operator {
|
||||
my $self = shift;
|
||||
my ($op) = @_;
|
||||
return defined $self->_overload_info_for($op);
|
||||
}
|
||||
|
||||
sub _overload_map {
|
||||
$_[0]->{_overload_map} ||= {};
|
||||
}
|
||||
|
||||
sub get_overloaded_operator {
|
||||
my $self = shift;
|
||||
my ($op) = @_;
|
||||
return $self->_overload_map->{$op} ||= $self->_overload_for($op);
|
||||
}
|
||||
|
||||
use constant _SET_FALLBACK_EACH_TIME => "$]" < 5.120;
|
||||
|
||||
sub add_overloaded_operator {
|
||||
my $self = shift;
|
||||
my ( $op, $overload ) = @_;
|
||||
|
||||
my %p = ( associated_metaclass => $self );
|
||||
if ( !ref $overload ) {
|
||||
%p = (
|
||||
%p,
|
||||
operator => $op,
|
||||
method_name => $overload,
|
||||
associated_metaclass => $self,
|
||||
);
|
||||
$p{method} = $self->get_method($overload)
|
||||
if $self->has_method($overload);
|
||||
$overload = Class::MOP::Overload->new(%p);
|
||||
}
|
||||
elsif ( !blessed $overload) {
|
||||
my ($coderef_package, $coderef_name) = Class::MOP::get_code_info($overload);
|
||||
$overload = Class::MOP::Overload->new(
|
||||
operator => $op,
|
||||
coderef => $overload,
|
||||
coderef_name => $coderef_name,
|
||||
coderef_package => $coderef_package,
|
||||
%p,
|
||||
);
|
||||
}
|
||||
|
||||
$overload->attach_to_class($self);
|
||||
$self->_overload_map->{$op} = $overload;
|
||||
|
||||
my %overload = (
|
||||
$op => $overload->has_coderef
|
||||
? $overload->coderef
|
||||
: $overload->method_name
|
||||
);
|
||||
|
||||
# Perl 5.10 and earlier appear to have a bug where setting a new
|
||||
# overloading operator wipes out the fallback value unless we pass it each
|
||||
# time.
|
||||
if (_SET_FALLBACK_EACH_TIME) {
|
||||
$overload{fallback} = $self->get_overload_fallback_value;
|
||||
}
|
||||
|
||||
$self->name->overload::OVERLOAD(%overload);
|
||||
}
|
||||
|
||||
sub remove_overloaded_operator {
|
||||
my $self = shift;
|
||||
my ($op) = @_;
|
||||
|
||||
delete $self->_overload_map->{$op};
|
||||
|
||||
# overload.pm provides no api for this - but the problem that makes this
|
||||
# necessary has been fixed in 5.18
|
||||
$self->get_or_add_package_symbol('%OVERLOAD')->{dummy}++
|
||||
if "$]" < 5.017000;
|
||||
|
||||
$self->remove_package_symbol('&(' . $op);
|
||||
}
|
||||
|
||||
sub get_overload_fallback_value {
|
||||
my $self = shift;
|
||||
return ($self->_overload_info_for('fallback') || {})->{value};
|
||||
}
|
||||
|
||||
sub set_overload_fallback_value {
|
||||
my $self = shift;
|
||||
my $value = shift;
|
||||
|
||||
$self->name->overload::OVERLOAD( fallback => $value );
|
||||
}
|
||||
|
||||
# We could cache this but we'd need some logic to clear it at all the right
|
||||
# times, which seems more tedious than it's worth.
|
||||
sub _overload_info {
|
||||
my $self = shift;
|
||||
return overload_info( $self->name ) || {};
|
||||
}
|
||||
|
||||
sub _overload_info_for {
|
||||
my $self = shift;
|
||||
my $op = shift;
|
||||
return overload_op_info( $self->name, $op );
|
||||
}
|
||||
|
||||
sub _overload_for {
|
||||
my $self = shift;
|
||||
my $op = shift;
|
||||
|
||||
my $map = $self->_overload_map;
|
||||
return $map->{$op} if $map->{$op};
|
||||
|
||||
my $info = $self->_overload_info_for($op);
|
||||
return unless $info;
|
||||
|
||||
my %p = (
|
||||
operator => $op,
|
||||
associated_metaclass => $self,
|
||||
);
|
||||
|
||||
if ( $info->{code} && !$info->{method_name} ) {
|
||||
$p{coderef} = $info->{code};
|
||||
@p{ 'coderef_package', 'coderef_name' }
|
||||
= $info->{code_name} =~ /(.+)::([^:]+)/;
|
||||
}
|
||||
else {
|
||||
$p{method_name} = $info->{method_name};
|
||||
if ( $self->has_method( $p{method_name} ) ) {
|
||||
$p{method} = $self->get_method( $p{method_name} );
|
||||
}
|
||||
}
|
||||
|
||||
return $map->{$op} = Class::MOP::Overload->new(%p);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# ABSTRACT: Methods for metaclasses which have overloads
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=encoding UTF-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Class::MOP::Mixin::HasOverloads - Methods for metaclasses which have overloads
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
version 2.2014
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This class implements methods for metaclasses which have overloads
|
||||
(L<Class::MOP::Clas> and L<Moose::Meta::Role>). See L<Class::MOP::Class> for
|
||||
API details.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Stevan Little <stevan@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Dave Rolsky <autarch@urth.org>
|
||||
|
||||
=item *
|
||||
|
||||
Jesse Luehrs <doy@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Shawn M Moore <sartak@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
|
||||
|
||||
=item *
|
||||
|
||||
Karen Etheridge <ether@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Florian Ragwitz <rafl@debian.org>
|
||||
|
||||
=item *
|
||||
|
||||
Hans Dieter Pearcey <hdp@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Chris Prather <chris@prather.org>
|
||||
|
||||
=item *
|
||||
|
||||
Matt S Trout <mstrout@cpan.org>
|
||||
|
||||
=back
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
This software is copyright (c) 2006 by Infinity Interactive, Inc.
|
||||
|
||||
This is free software; you can redistribute it and/or modify it under
|
||||
the same terms as the Perl 5 programming language system itself.
|
||||
|
||||
=cut
|
||||
Reference in New Issue
Block a user