| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | package Regexp::Whitespace::Builder; | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 2 |  |  | 2 |  | 28 | use 5.008; | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 70 |  | 
| 5 | 2 |  |  | 2 |  | 9 | use strict; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 54 |  | 
| 6 | 2 |  |  | 2 |  | 9 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 74 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our $VERSION = '0.001_0'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 2 |  |  | 2 |  | 2041 | use Regexp::Whitespace::Parser (); | 
|  | 2 |  |  |  |  | 7 |  | 
|  | 2 |  |  |  |  | 71 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 2 |  |  | 2 |  | 18 | use constant _debug => 0; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 264 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 2 |  |  | 2 |  | 2785 | use if _debug, DDS => 'Dump'; | 
|  | 2 |  |  |  |  | 24 |  | 
|  | 2 |  |  |  |  | 10 |  | 
| 15 |  |  |  |  |  |  | #use charnames ':full'; # FIXME make it conditional | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub build { | 
| 18 | 16 |  |  | 16 | 0 | 540 | my $self = shift; | 
| 19 | 16 |  |  |  |  | 32 | my $re = shift; | 
| 20 | 16 |  |  |  |  | 24 | my $flags = shift; | 
| 21 | 16 | 50 |  |  |  | 59 | die "flags must be 'w' in this early version" if $flags ne 'w'; | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 16 |  |  |  |  | 1296 | my $p = Regexp::Whitespace::Parser->new( $re ); | 
| 24 | 16 |  |  |  |  | 886 | $p->parse; | 
| 25 | 16 |  |  |  |  | 9409 | my $t = $p->top; | 
| 26 | 16 | 50 | 33 |  |  | 106 | die "could not parse $re: " . $p->error unless $t || $p->error; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 16 |  |  |  |  | 17 | Dump( $t ) if _debug; | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | # walk the RE tree doing transformations [\s] -> \s+ | 
| 31 | 16 |  |  |  |  | 71 | my $nt = $t->convert; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 16 |  |  |  |  | 30 | Dump( $nt ) if _debug; | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 16 |  |  |  |  | 313 | my $regex = $nt->fullstring; | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | # FIXME: there's a bug here if we're using \N{named} escapes | 
| 38 |  |  |  |  |  |  | #   because they are replaced at compile time and | 
| 39 |  |  |  |  |  |  | #   would need something like eval qq{use charnames ':full'; qr/$s/} | 
| 40 |  |  |  |  |  |  | # | 
| 41 |  |  |  |  |  |  | # Instead, we should mark (TODO) there is named escapes involved | 
| 42 |  |  |  |  |  |  | #   and do a substitution   s/\N{([^}])}/charnames::vianame($1)/ge | 
| 43 |  |  |  |  |  |  | #   before mounting the regex | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 16 | 50 |  |  |  | 677 | if ( $regex =~ /\A [(][?]-imsx: (.*) [)] \z/sx ) { # FIXME | 
| 46 |  |  |  |  |  |  | #warn "# GOT"; | 
| 47 | 16 |  |  |  |  | 340 | return qr/$1/; | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  | #warn "# FALLBACK"; | 
| 50 | 0 |  |  |  |  |  | return qr/$regex/; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | 1; |