Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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: http://search.cpan.org/dist/perl-5.14.0-RC1/pod/perldelta.pod#Stringification_of_regexes_has_changed

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
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1027714]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2015-07-06 00:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls