/usr/lib/perl5/Moose/Meta/Method/Accessor/Native/Writer.pm is in libmoose-perl 2.0401-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 167 168 169 | package Moose::Meta::Method::Accessor::Native::Writer;
BEGIN {
$Moose::Meta::Method::Accessor::Native::Writer::AUTHORITY = 'cpan:STEVAN';
}
{
$Moose::Meta::Method::Accessor::Native::Writer::VERSION = '2.0401';
}
use strict;
use warnings;
use List::MoreUtils qw( any );
use Moose::Role;
with 'Moose::Meta::Method::Accessor::Native';
requires '_potential_value';
sub _generate_method {
my $self = shift;
my $inv = '$self';
my $slot_access = $self->_get_value($inv);
return (
'sub {',
'my ' . $inv . ' = shift;',
$self->_inline_curried_arguments,
$self->_inline_writer_core($inv, $slot_access),
'}',
);
}
sub _inline_writer_core {
my $self = shift;
my ($inv, $slot_access) = @_;
my $potential = $self->_potential_value($slot_access);
my $old = '@old';
my @code;
push @code, (
$self->_inline_check_argument_count,
$self->_inline_process_arguments($inv, $slot_access),
$self->_inline_check_arguments('for writer'),
$self->_inline_check_lazy($inv, '$type_constraint', '$type_coercion', '$type_message'),
);
if ($self->_return_value($slot_access)) {
# some writers will save the return value in this variable when they
# generate the potential value.
push @code, 'my @return;'
}
push @code, (
$self->_inline_coerce_new_values,
$self->_inline_copy_native_value(\$potential),
$self->_inline_tc_code($potential, '$type_constraint', '$type_coercion', '$type_message'),
$self->_inline_get_old_value_for_trigger($inv, $old),
$self->_inline_capture_return_value($slot_access),
$self->_inline_set_new_value($inv, $potential, $slot_access),
$self->_inline_trigger($inv, $slot_access, $old),
$self->_inline_return_value($slot_access, 'for writer'),
);
return @code;
}
sub _inline_process_arguments { return }
sub _inline_check_arguments { return }
sub _inline_coerce_new_values { return }
sub _writer_value_needs_copy {
my $self = shift;
return $self->_constraint_must_be_checked;
}
sub _constraint_must_be_checked {
my $self = shift;
my $attr = $self->associated_attribute;
return $attr->has_type_constraint
&& (!$self->_is_root_type( $attr->type_constraint )
|| ( $attr->should_coerce && $attr->type_constraint->has_coercion)
);
}
sub _is_root_type {
my $self = shift;
my ($type) = @_;
my $name = $type->name;
return any { $name eq $_ } @{ $self->root_types };
}
sub _inline_copy_native_value {
my $self = shift;
my ($potential_ref) = @_;
return unless $self->_writer_value_needs_copy;
my $code = 'my $potential = ' . ${$potential_ref} . ';';
${$potential_ref} = '$potential';
return $code;
}
around _inline_tc_code => sub {
my $orig = shift;
my $self = shift;
my ($value, $tc, $coercion, $message, $for_lazy) = @_;
return unless $for_lazy || $self->_constraint_must_be_checked;
return $self->$orig(@_);
};
around _inline_check_constraint => sub {
my $orig = shift;
my $self = shift;
my ($value, $tc, $message, $for_lazy) = @_;
return unless $for_lazy || $self->_constraint_must_be_checked;
return $self->$orig(@_);
};
sub _inline_capture_return_value { return }
sub _inline_set_new_value {
my $self = shift;
return $self->_inline_store_value(@_)
if $self->_writer_value_needs_copy
|| !$self->_slot_access_can_be_inlined
|| !$self->_get_is_lvalue;
return $self->_inline_optimized_set_new_value(@_);
}
sub _get_is_lvalue {
my $self = shift;
return $self->associated_attribute->associated_class->instance_metaclass->inline_get_is_lvalue;
}
sub _inline_optimized_set_new_value {
my $self = shift;
return $self->_inline_store_value(@_);
}
sub _return_value {
my $self = shift;
my ($slot_access) = @_;
return $slot_access;
}
no Moose::Role;
1;
|