Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: YAML: regex stringification has changed (bless/overload not YAML::XS)

by Anonymous Monk
on Apr 09, 2013 at 13:19 UTC ( #1027731=note: print w/ replies, xml ) Need Help??


in reply to Re: YAML: regex stringification has changed (bless/overload)
in thread YAML: regex stringification has changed

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


Comment on Re^2: YAML: regex stringification has changed (bless/overload not YAML::XS)
Download Code
Re^3: YAML: regex stringification has changed (bless/overload not YAML::XS)
by Boldra (Deacon) on Apr 09, 2013 at 14:36 UTC
    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: note [id://1027731]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-11-27 17:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (186 votes), past polls