Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with blessed regexes #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aferreira
Copy link

Regex objects (like qr/Foo/) are kind of special in Perl
because they have a REGEXP reftype but are blessed into "Regexp"
package. That means it is not desirable to dump qr/Foo/ into

bless(qr/Foo/, "Regexp")

which is redudant, but if the blessed package is other than "Regexp"
it is necessary to resort to the "bless" expression, as in

bless(qr/Foo/, "Regexp::Alt")

Previous to this change, this was the output by Data::Dump for such cases:

perl -MData::Dump=pp -e 'pp(bless qr/Foo/, "Regexp::Alt")'
do {
  my $a = bless(do{\(my $o = do{my $fix})}, "Regexp::Alt");
  $$a = $a;
  $a;
}

From this change on, the output becomes

perl -MData::Dump=pp -e 'pp(bless qr/Foo/, "Regexp::Alt")'
bless(qr/Foo/, "Regexp::Alt")

which evaluates correctly and that follows what Data::Dumper
and Data::Dump::Streamer do.

Regex objects (like qr/Foo/) are kind of special in Perl
because they have a REGEXP reftype but are blessed into the "Regexp"
package. That means qr/Foo/ is dumped as

    qr/Foo/

while regexes blessed to other packages than "Regexp"
should produce outputs like

    bless(qr/Foo/, "Regexp::Alt")
as they don't have much in common. And REGEXP are always refs
like other types as CODE, ARRAY, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant