Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add segment counter to sink, record charset

  • Loading branch information...
commit fa0006fff2cb08154cd98eb94e959c6ae4a93274 1 parent 32af30f
@sorear authored
Showing with 6 additions and 1 deletion.
  1. +3 −0  lib/X12/Schema/TokenSink.pm
  2. +3 −1 t/01-sink.t
View
3  lib/X12/Schema/TokenSink.pm
@@ -4,12 +4,14 @@ use Moose;
use namespace::autoclean;
has delim_re => (is => 'ro', isa => 'RegexpRef', init_arg => undef);
+has non_charset_re => (is => 'ro', isa => 'RegexpRef', default => sub { qr/(?!)/ });
has [qw( segment_term element_sep component_sep )] => (is => 'ro', isa => 'Str', required => 1);
has repeat_sep => (is => 'ro', isa => 'Str');
has output => (is => 'rw', isa => 'Str', default => '', init_arg => undef);
has output_func => (is => 'rw', isa => 'CodeRef');
+has segment_counter => (is => 'rw', isa => 'Int', default => 0, init_arg => undef);
# DIVERSITY: this will need to include flags to control the output in other ways, such as UN/EDIFACT mode, whether to use exponential notation, etc
@@ -34,6 +36,7 @@ sub BUILD {
sub segment {
my ($self, $seg) = @_;
+ $self->{segment_counter}++;
$self->{output_func} ? $self->{output_func}->($seg) : ( $self->{output} .= $seg );
}
View
4 t/01-sink.t
@@ -1,6 +1,6 @@
use strict;
use warnings;
-use Test::More tests => 26;
+use Test::More tests => 28;
use Test::Exception;
BEGIN { use_ok "X12::Schema::TokenSink"; }
@@ -55,9 +55,11 @@ my $ext = '';
$baseline = new_ok 'X12::Schema::TokenSink', [%args, output_func => sub { $ext .= $_[0] }], 'new with output_func';
is $ext, '', 'external output initially empty';
+is $baseline->segment_counter, 0, 'ctr initially 0';
$baseline->segment('foo');
is $ext, 'foo', 'first external output recorded';
$baseline->segment('bar');
is $ext, 'foobar', 'subseq external output recorded';
+is $baseline->segment_counter, 2, 'ctr records segments';
Please sign in to comment.
Something went wrong with that request. Please try again.