use YAPE::Regex; my $p = YAPE::Regex->new(qr//); $p->YAPE::Regex::Extensible::steal_pat; package YAPE::Regex::Extensible; use base 'YAPE::Regex'; use B qw(svref_2object); use Devel::Pointer; sub steal_pat { my $self = shift; $self->{'pat'} = {}; my $sub = \&YAPE::Regex::next; my $osub = svref_2object( $sub ); # Unpack next()'s pad list into an array of names and values. my ($names, $values) = map [ $_->ARRAY ], $osub->PADLIST->ARRAY; # Fetch the first HV associated with the name '%pat' my $h; for my $i (0 .. $#$names) { if ( $names->[$i]->can('PV') and $names->[$i]->PV eq '%pat') { $h = $values->[$i]; last; } } # $$h is the address of the hash # Use Devel::Pointer to construct a reference to it. $self->{'pat'} = unsmash_hv( $$h ); }