File Coverage

blib/lib/MARC/Spec/Comparisonstring.pm
Criterion Covered Total %
statement 19 22 86.3
branch 3 4 75.0
condition n/a
subroutine 5 6 83.3
pod 1 3 33.3
total 28 35 80.0


line stmt bran cond sub pod time code
1             package MARC::Spec::Comparisonstring;
2              
3 14     14   15686 use Carp qw(croak);
  14         16  
  14         657  
4 14     14   441 use Moo;
  14         9010  
  14         59  
5 14     14   4339 use namespace::clean;
  14         8106  
  14         60  
6              
7             our $VERSION = '0.1.4';
8              
9             has raw => (
10             is => 'rwp',
11             required => 1
12             );
13              
14             has comparable => (
15             is => 'rwp'
16             );
17              
18             sub BUILDARGS {
19 87     87 0 7680 my ( $class, @args ) = @_;
20 87 50       240 unshift @args, "raw" if @args % 2 == 1;
21 87         1245 return { @args };
22             }
23              
24             sub BUILD {
25 87     87 0 754 my ($self, $args) = @_;
26            
27             # char of list ${}!=~?|\s must be escaped if not at index 0*
28 87 100       344 croak "MARCspec Comparisonstring exception. Unescaped character detected. Tried to parse: ".$self->raw
29             unless($self->raw =~ /^(.(?:[^\$\{\}\!\=\~\?\|\s]|(?<=\\\\)[\$\{\}\!\=\~\?\|])*)$/s);
30              
31 86         92 my $comparable = $self->raw;
32 86         75 my $replace = ' ';
33 86         81 $comparable =~ s{\\s}{$replace}g;
34 86         117 $self->_set_comparable($comparable);
35 86         1325 return;
36             }
37              
38             sub to_string {
39 0     0 1   my ($self) = @_;
40 0           my $string = '\\'.$self->raw;
41 0           return $string;
42             }
43             1;
44              
45             __END__