File Coverage

blib/lib/App/HL7/Compare/Parser/MessageConfig.pm
Criterion Covered Total %
statement 31 31 100.0
branch 2 4 50.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 41 44 93.1


line stmt bran cond sub pod time code
1             package App::HL7::Compare::Parser::MessageConfig;
2             $App::HL7::Compare::Parser::MessageConfig::VERSION = '0.001';
3 3     3   45 use v5.10;
  3         12  
4 3     3   17 use strict;
  3         7  
  3         78  
5 3     3   22 use warnings;
  3         8  
  3         111  
6              
7 3     3   19 use Moo;
  3         7  
  3         27  
8 3     3   1123 use Mooish::AttributeBuilder -standard;
  3         6  
  3         19  
9 3     3   1977 use Types::Common::String qw(StrLength);
  3         176718  
  3         33  
10 3     3   3476 use Carp qw(croak);
  3         9  
  3         1168  
11              
12             has param 'segment_separator' => (
13             isa => StrLength [1, 2],
14             writer => 1,
15             default => sub { "\n" },
16             );
17              
18             has option 'field_separator' => (
19             isa => StrLength [1, 1],
20             writer => 1,
21             );
22              
23             has option 'component_separator' => (
24             isa => StrLength [1, 1],
25             writer => 1,
26             );
27              
28             has option 'repetition_separator' => (
29             isa => StrLength [1, 1],
30             writer => 1,
31             );
32              
33             has option 'escape_character' => (
34             isa => StrLength [1, 1],
35             writer => 1,
36             );
37              
38             has option 'subcomponent_separator' => (
39             isa => StrLength [1, 1],
40             writer => 1,
41             );
42              
43             sub from_MSH
44             {
45 8     8 0 22 my ($self, $input) = @_;
46 8         105 $input =~ s/\AMSH//;
47              
48 8         32 my @order = qw(
49             field_separator
50             component_separator
51             repetition_separator
52             escape_character
53             subcomponent_separator
54             );
55              
56 8 50       26 croak 'Not enough input to read message control characters'
57             unless length $input >= @order;
58              
59 8         43 my @characters = split //, substr $input, 0, scalar @order;
60 8         22 foreach my $field (@order) {
61 40         908 my $setter = "set_$field";
62 40         75 my $predicate = "has_$field";
63              
64 40         65 my $character = shift @characters;
65 40 50       142 next if $self->$predicate;
66 40         715 $self->$setter($character);
67             }
68             }
69              
70             1;
71