/usr/lib/perl5/Moose/Meta/Method/Accessor/Native.pm is in libmoose-perl 2.1005-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | package Moose::Meta::Method::Accessor::Native;
BEGIN {
$Moose::Meta::Method::Accessor::Native::AUTHORITY = 'cpan:STEVAN';
}
{
$Moose::Meta::Method::Accessor::Native::VERSION = '2.1005';
}
use strict;
use warnings;
use Carp qw( confess );
use Scalar::Util qw( blessed weaken );
use Moose::Role;
around new => sub {
my $orig = shift;
my $class = shift;
my %options = @_;
$options{curried_arguments} = []
unless exists $options{curried_arguments};
confess 'You must supply a curried_arguments which is an ARRAY reference'
unless $options{curried_arguments}
&& ref($options{curried_arguments}) eq 'ARRAY';
my $attr_context = $options{attribute}->definition_context;
my $desc = 'native delegation method ';
$desc .= $options{attribute}->associated_class->name;
$desc .= '::' . $options{name};
$desc .= " ($options{delegate_to_method})";
$desc .= " of attribute " . $options{attribute}->name;
$options{definition_context} = {
%{ $attr_context || {} },
description => $desc,
};
$options{accessor_type} = 'native';
return $class->$orig(%options);
};
sub _new {
my $class = shift;
my $options = @_ == 1 ? $_[0] : {@_};
return bless $options, $class;
}
sub root_types { (shift)->{'root_types'} }
sub _initialize_body {
my $self = shift;
$self->{'body'} = $self->_compile_code( [$self->_generate_method] );
return;
}
sub _inline_curried_arguments {
my $self = shift;
return unless @{ $self->curried_arguments };
return 'unshift @_, @curried;';
}
sub _inline_check_argument_count {
my $self = shift;
my @code;
if (my $min = $self->_minimum_arguments) {
push @code, (
'if (@_ < ' . $min . ') {',
$self->_inline_throw_error(
sprintf(
'"Cannot call %s without at least %s argument%s"',
$self->delegate_to_method,
$min,
($min == 1 ? '' : 's'),
)
) . ';',
'}',
);
}
if (defined(my $max = $self->_maximum_arguments)) {
push @code, (
'if (@_ > ' . $max . ') {',
$self->_inline_throw_error(
sprintf(
'"Cannot call %s with %s argument%s"',
$self->delegate_to_method,
$max ? "more than $max" : 'any',
($max == 1 ? '' : 's'),
)
) . ';',
'}',
);
}
return @code;
}
sub _inline_return_value {
my $self = shift;
my ($slot_access, $for_writer) = @_;
return 'return ' . $self->_return_value($slot_access, $for_writer) . ';';
}
sub _minimum_arguments { 0 }
sub _maximum_arguments { undef }
override _get_value => sub {
my $self = shift;
my ($instance) = @_;
return $self->_slot_access_can_be_inlined
? super()
: $instance . '->$reader';
};
override _inline_store_value => sub {
my $self = shift;
my ($instance, $value) = @_;
return $self->_slot_access_can_be_inlined
? super()
: $instance . '->$writer(' . $value . ');';
};
override _eval_environment => sub {
my $self = shift;
my $env = super();
$env->{'@curried'} = $self->curried_arguments;
return $env if $self->_slot_access_can_be_inlined;
my $reader = $self->associated_attribute->get_read_method_ref;
$reader = $reader->body if blessed $reader;
$env->{'$reader'} = \$reader;
my $writer = $self->associated_attribute->get_write_method_ref;
$writer = $writer->body if blessed $writer;
$env->{'$writer'} = \$writer;
return $env;
};
sub _slot_access_can_be_inlined {
my $self = shift;
return $self->is_inline && $self->_instance_is_inlinable;
}
no Moose::Role;
1;
|