sub init {
my $self = shift;
- @{$self}{ qw(Declarator Offset) } = @_;
+ @{$self}{ qw(Declarator Offset WarningOnRedefined) } = @_;
return $self;
}
return $self->{Declarator}
}
+sub warning_on_redefine {
+ my $self = shift;
+ return $self->{WarningOnRedefined}
+}
+
sub skip_declarator {
my $self = shift;
my $decl = $self->declarator;
*{$args{into}.'::'.$args{name}} = sub (&) {};
}
+ my $warnings = warnings::enabled("redefine");
my $ctx = $class->new(%args);
Devel::Declare->setup_for(
$args{into},
- { $args{name} => { const => sub { $ctx->parser(@_) } } }
+ { $args{name} => { const => sub { $ctx->parser(@_, $warnings) } } }
);
}
my $code = shift;
# So caller() gets the subroutine name
no strict 'refs';
- *{$name} = subname $name => $code;
+ my $installer = $self->warning_on_redefine
+ ? sub { *{$name} = subname $name => $code; }
+ : sub { no warnings 'redefine';
+ *{$name} = subname $name => $code; };
+ $installer->();
return;
};
} else {