| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Badger::Data::Facet::Text::Whitespace; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | use Badger::Data::Facet::Class | 
| 4 | 1 |  |  |  |  | 10 | version   => 0.01, | 
| 5 |  |  |  |  |  |  | type      => 'text', | 
| 6 |  |  |  |  |  |  | args      => 'whitespace', | 
| 7 |  |  |  |  |  |  | constant  => { | 
| 8 |  |  |  |  |  |  | PRESERVE => 0, | 
| 9 |  |  |  |  |  |  | FOLD     => 1, | 
| 10 |  |  |  |  |  |  | COLLAPSE => 2, | 
| 11 | 1 |  |  | 1 |  | 8 | }; | 
|  | 1 |  |  |  |  | 2 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | our $ACTION = { | 
| 14 |  |  |  |  |  |  | preserve => PRESERVE, | 
| 15 |  |  |  |  |  |  | fold     => FOLD, | 
| 16 |  |  |  |  |  |  | collapse => COLLAPSE, | 
| 17 |  |  |  |  |  |  | }; | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub init { | 
| 21 | 2 |  |  | 2 | 1 | 4 | my ($self, $config) = @_; | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 2 | 50 |  |  |  | 8 | $self->SUPER::init($config) | 
| 24 |  |  |  |  |  |  | || return; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | # option must have an entry in $ACCEPT which we store in $self->{ action } | 
| 27 |  |  |  |  |  |  | return $self->error_msg( whitespace => $self->{ whitespace }, join(', ', keys %$ACTION) ) | 
| 28 | 2 | 50 |  |  |  | 6 | unless defined ($self->{ action } = $ACTION->{ $self->{ whitespace } }); | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 2 |  |  |  |  | 4 | return $self; | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | sub validate { | 
| 35 | 2 |  |  | 2 | 1 | 11 | my ($self, $text, $type) = @_; | 
| 36 |  |  |  |  |  |  | my $action = $self->{ action }      # do nothing for PRESERVE | 
| 37 | 2 |  | 50 |  |  | 3 | || return $text; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 2 |  |  |  |  | 5 | for ($$text) { | 
| 40 | 2 |  |  |  |  | 10 | s/[\r\n\t]/ /g; | 
| 41 | 2 | 100 |  |  |  | 5 | if ($action == COLLAPSE) { | 
| 42 | 1 |  |  |  |  | 5 | s/ +/ /g; | 
| 43 | 1 |  |  |  |  | 2 | s/^ +//; | 
| 44 | 1 |  |  |  |  | 4 | s/ +$//; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 2 |  |  |  |  | 5 | return $text; | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | 1; | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | __END__ |