Commit | Line | Data |
04e05413 |
1 | package Moose::Meta::Method::Accessor::Native::Counter::Writer; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
10bd99ec |
6 | our $VERSION = '1.14'; |
04e05413 |
7 | $VERSION = eval $VERSION; |
8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | |
10 | use base 'Moose::Meta::Method::Accessor::Native::Writer'; |
11 | |
04e05413 |
12 | sub _constraint_must_be_checked { |
13 | my $self = shift; |
14 | |
15 | my $attr = $self->associated_attribute; |
16 | |
17 | return $attr->has_type_constraint |
18 | && ( $attr->type_constraint->name =~ /^(?:Num|Int)$/ |
19 | || ( $attr->should_coerce && $attr->type_constraint->has_coercion ) ); |
20 | } |
21 | |
22 | sub _inline_check_coercion { |
23 | my ( $self, $value ) = @_; |
24 | |
25 | my $attr = $self->associated_attribute; |
26 | |
27 | return '' |
28 | unless $attr->should_coerce && $attr->type_constraint->has_coercion; |
29 | |
30 | # We want to break the aliasing in @_ in case the coercion tries to make a |
31 | # destructive change to an array member. |
32 | return "$value = $attr->type_constraint->coerce($value);"; |
33 | } |
34 | |
35 | 1; |