;
}
+sub _check_overwrite
+{
+ my ($pkg, $method, $type) = @_;
+ *{_getglob("${pkg}::${method}")}{CODE} and
+ die "You cannot overwrite a locally defined method ($method) with a @{[ $type || 'accessor' ]}";
+}
+
sub generate_method {
my ($self, $into, $name, $spec, $quote_opts) = @_;
$name =~ s/^\+//;
my %methods;
if (my $reader = $spec->{reader}) {
+ _check_overwrite($into, $reader, 'reader');
if (our $CAN_HAZ_XS && $self->is_simple_get($name, $spec)) {
$methods{$reader} = $self->_generate_xs(
getters => $into, $reader, $name, $spec
}
}
if (my $accessor = $spec->{accessor}) {
+ _check_overwrite($into, $accessor, 'accessor');
if (
our $CAN_HAZ_XS
&& $self->is_simple_get($name, $spec)
}
}
if (my $writer = $spec->{writer}) {
+ _check_overwrite($into, $writer, 'writer');
if (
our $CAN_HAZ_XS
&& $self->is_simple_set($name, $spec)
}
}
if (my $pred = $spec->{predicate}) {
+ _check_overwrite($into, $pred, 'predicate');
$methods{$pred} =
quote_sub "${into}::${pred}" =>
' '.$self->_generate_simple_has('$_[0]', $name, $spec)."\n"
_install_coderef( "${into}::$spec->{builder}" => $spec->{builder_sub} );
}
if (my $cl = $spec->{clearer}) {
+ _check_overwrite($into, $cl, 'clearer');
$methods{$cl} =
quote_sub "${into}::${cl}" =>
$self->_generate_simple_clear('$_[0]', $name, $spec)."\n"
};
foreach my $spec (@specs) {
my ($proxy, $target, @args) = @$spec;
+ _check_overwrite($into, $proxy, 'delegation');
$self->{captures} = {};
- if ( *{_getglob("${into}::${proxy}")}{CODE} ) {
- die "You cannot overwrite a locally defined method ($proxy) with a delegation";
- }
$methods{$proxy} =
quote_sub "${into}::${proxy}" =>
$self->_generate_delegation($asserter, $target, \@args),