-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add explicit PICA Patch parser and writer
- Loading branch information
Showing
12 changed files
with
178 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package PICA::Parser::Patch; | ||
use v5.14.1; | ||
|
||
our $VERSION = '2.11'; | ||
|
||
use parent 'PICA::Parser::Plain'; | ||
|
||
use Carp qw(croak); | ||
|
||
sub _new { | ||
my $self = PICA::Parser::Base::_new(@_); | ||
$self->annotated = undef; | ||
$self->strict = 1; | ||
$self; | ||
} | ||
|
||
sub parse_field { | ||
my ($self, $field) = @_; | ||
$field = $self->SUPER::parse_field($field); | ||
|
||
return [@$field, " "] unless @$field % 2; | ||
|
||
my $char = $field->[$#$field]; | ||
croak "Invalid annotation: '$char'" if $char !~ /^[ +-]$/; | ||
|
||
return $field; | ||
} | ||
|
||
1; | ||
__END__ | ||
=head1 NAME | ||
PICA::Parser::Plain - Plain PICA+ format serializer | ||
=head2 DESCRIPTION | ||
This is basically L<PICA::Parser::Plain> with option C<strict> enabled and required | ||
or empty annotation character C<+>, C<-> or space for each field. | ||
The counterpart of this module is L<PICA::Writer::Patch>. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package PICA::Writer::Patch; | ||
use v5.14.1; | ||
|
||
our $VERSION = '2.11'; | ||
|
||
use Carp qw(croak); | ||
|
||
use parent 'PICA::Writer::Plain'; | ||
|
||
sub write_field { | ||
my ($self, $field) = @_; | ||
|
||
if (@$field % 2) { | ||
my $char = $field->[$#$field]; | ||
croak "Invalid annotation: '$char'" if $char !~ /^[ +-]$/; | ||
} | ||
else { | ||
$field = [@$field, " "]; | ||
} | ||
PICA::Writer::Base::write_field($self, $field); | ||
} | ||
|
||
1; | ||
__END__ | ||
=head1 NAME | ||
PICA::Writer::Plain - Plain PICA+ format serializer | ||
=head2 DESCRIPTION | ||
This is basically L<PICA::Writer::Plain> with option C<annotate> enabled. In | ||
addition writing an annotated field with result in an error if the field is | ||
annotated with another character but C<+>, C<-> or space. | ||
The counterpart of this module is L<PICA::Parser::Patch>. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters