after clear_globref => sub {
my ($self) = @_;
$self->stash->remove_symbol('&'.$self->keyword_name);
+ $self->globref_refcount(undef);
+ $self->restore_shadow;
+};
+
+sub restore_shadow {
+ my ($self) = @_;
if (my $shadowed = $self->_shadowed_sub) {
{ no warnings 'redefine', 'prototype'; *{$self->globref} = $shadowed; }
}
- $self->globref_refcount(undef);
-};
+}
has globref_refcount => (is => 'rw');
has code => (is => 'rw', default => sub { '' });
-has active_keyword => (is => 'rw', clearer => 1);
+has current_keyword => (is => 'rw', clearer => 1);
+has keyword_matched => (is => 'rw');
sub get_next {
my ($self) = @_;
$self->${\$self->re_add};
return ('', 0);
}
- if (my $keyword = $self->active_keyword) {
- $self->clear_active_keyword;
- $keyword->clear_globref;
- return $keyword->parse($self);
- }
- for my $keyword (@{$self->keywords}) {
- if ($keyword->have_match) {
- $self->active_keyword($keyword);
+ if (my $keyword = $self->current_keyword) {
+ if ($self->keyword_matched) {
+ $keyword->clear_globref;
+ $self->clear_current_keyword;
+ $self->short_circuit(1);
+ return $keyword->parse($self);
+ }
+ elsif ($keyword->have_match) {
+ $self->keyword_matched(1);
$self->short_circuit(1);
my $match = $self->current_match;
my $end = $match eq '{' ? '}'
: '';
return ("$end;", 1);
}
+ else {
+ $keyword->restore_shadow;
+ $self->clear_current_keyword;
+ }
}
return $self->check_match;
}
) {
$keyword->install_matcher($matches->[0]);
$self->current_match($matches->[0]);
+ $self->current_keyword($keyword);
+ $self->keyword_matched(0);
$self->short_circuit(1);
return ($stripped, 1);
}