Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

YAML: regex stringification has changed

by Boldra (Deacon)
on Apr 09, 2013 at 11:52 UTC ( #1027714=perlquestion: print w/replies, xml ) Need Help??
Boldra has asked for the wisdom of the Perl Monks concerning the following question:

I'm migrating from perl 5.10 to perl 5.16, and I hit this:

Unfortunately the workaround described in the perldelta doc (using the regexp_pattern import from re) would be very messy to implement, because most of our stringification/instantiation goes through YAML::Dump and YAML::Load (or even YAML::XS::Load or YAML::Any::Load). I could overwrite YAML::Type::regexp::yaml_load, but I don't think that would work in YAML::XS.

Has anyone else encountered this/have any suggestions?

Many thanks!

- Boldra
  • Comment on YAML: regex stringification has changed

Replies are listed 'Best First'.
Re: YAML: regex stringification has changed (bless/overload)
by Anonymous Monk on Apr 09, 2013 at 12:12 UTC

      It works with pure-perl but not YAML::XS

      #!/usr/bin/perl -- use strict; use warnings; print qr{yo}usim, "\n"; $::yo++; print qr{yo}usim, "\n"; $::yo--; use YAML::XS; print YAML::XS::Dump( [ qr{yo}usim ] ), "\n"; package Regexp; use Data::Dump; sub ixsm { #~ (?s-xim:s) my( $i )=@_; my %onoff = ( qw/ s 0 i 0 m 0 x 0 / ); $onoff{$1}++ while $i =~ /(.)/g;; delete $onoff{$_} for qw/ o a l u d /; my @off; my @on; while( my($k,$v) = each %onoff ){ push @on, $k if $v; push @off, $k if not $v; } my $on = join'',@on; my $off = join'',@off; my $ret = "(?$on"; $ret .="-$off" if length $off; $ret; } use overload '""' => sub { my( $self_operand_overloaded, $other_operand, $other_operand_was_o +n_the_left_side ) = @_; my( $patt, $mods ) = re::regexp_pattern( $self_operand_overloaded +); $::yo and return ixsm($mods).':'.$patt.')'; ## oldstyle return $self_operand_overloaded; ## modern }; __END__ (?^umsi:yo) (?msi-x:yo) --- - !!perl/regexp (?^umsi:yo)
      Seems YAML::XS doesn't process overloads, peeks inside like Devel::Peek
        Thanks for checking that avenue. I was pretty sure YAML::XS was going to be a problem. I think it's going to be easiest for me to start saving regexes as strings instead of perl objects. I will also have to delete any regexes I accidentally load from old data, because if I read/write them a few times, they eventually become unparsable. The bug hit when
        match: !!perl/regexp (?i-xsm:OK\ Server\ Connection\ 1\.001)
        became something like
        match: !!perl/regexp (?-u(?-u(?-u(?i-xsm:OK\ Server\ Connection\ 1 +\.001))))

        - Boldra

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1027714]
Approved by marto
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2017-07-20 22:15 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (316 votes). Check out past polls.