in reply to Re: Re: How to view contents of a blessed Regular Expression?
in thread How to view contents of a blessed Regular Expression?

qr// gives you a reference to a scalar that is already blessed into the Regexp package. So you are reblessing it which stops Regexp methods/overloads from working on it after that point. Stringification is a Regexp overload and so no longer works. If you want stringification again, then you'd need to provide such a overload via your AltRegex package.

        - tye (but my friends call me "Tye")
  • Comment on (tye)Re: How to view contents of a blessed Regular Expression?

Replies are listed 'Best First'.
Re: (tye)Re: How to view contents of a blessed Regular Expression?
by bikeNomad (Priest) on Jul 16, 2001 at 19:48 UTC
    But if you inherit from Regexp, wouldn't the overload be inherited as well? i.e. this works:

    use strict; $^W++; package A; use overload '""' => sub { overload::StrVal(shift) . 'xx' }; package B; @B::ISA = 'A'; package main; my $a = bless \(my $aa = 'abc'), 'A'; print "$a\n"; bless $a, 'B'; # re-bless print "$a\n";
      Well, as I thought, this is beyond my grasp right now. I think I'm getting too bogged down in the details. I'll bookmark this node and come back to it in a couple months.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop";
      $nysus = $PM . $MCF;
      Click here if you love Perl Monks

        Regex's stringify overload isn't a regular overload via overload.pm, its a block of code in perl's main stringify routine: sv.c:sv_2pv_flags(). This explicitly checks for a package name of Regex up through perl 5.8.0, so having your new regex class be a subclass of Regex does nothing (except make isa("Regex") checks work. For 5.8.1 and later, the needless package name check is omitted, so reblessed regexes should Just Work.