Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: YAML: regex stringification has changed (bless/overload)

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


in reply to YAML: regex stringification has changed

Has anyone else encountered this/have any suggestions?

Store Regexp::English objects? :)

I once patched YAPE::Regex::Explain to recognize the new syntax (?^i:i) and (?i-xsm:i) but the whole thing left me disgusted with the obscene amount of catching up required just to tokenize the regex -- something the engine already does

Maybe you could use re::engine::Hooks or probably overload to hook-into it globally

Maybe see example in http://perl5.git.perl.org/perl.git/blob/HEAD:/lib/overload.t


Comment on Re: YAML: regex stringification has changed (bless/overload)
Re^2: YAML: regex stringification has changed (bless/overload not YAML::XS)
by Anonymous Monk on Apr 09, 2013 at 13:19 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: note [id://1027717]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-08-28 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls