MARC-Spec-2.0.3/0000755001161400116140000000000013215154435012255 5ustar devel2devel2MARC-Spec-2.0.3/t/0000755001161400116140000000000013215154435012520 5ustar devel2devel2MARC-Spec-2.0.3/t/09-parser.t0000644001161400116140000000064313215154435014432 0ustar devel2devel2use Test::More; use MARC::Spec::Parser; my $parser = MARC::Spec::parse('006[0-3]^1{$b}'); ok $parser->indicator->position eq '1', 'indicator position'; ok $parser->indicator->subspecs->[0]->left->field->tag eq '006', 'subspec field tag'; $parser = MARC::Spec::parse('006{^1}'); ok $parser->field->subspecs->[0]->right->indicator->position eq '1', 'subspec indicator position abbreviation1'; done_testing();MARC-Spec-2.0.3/t/01-parser.t0000755001161400116140000000250313215154435014422 0ustar devel2devel2use Test::More; use MARC::Spec::Parser; my $parser = MARC::Spec::parse('006[0-3]/1-3{LDR/0=\A|LDR/0=\X}{LDR/1!=\X}'); # checking field ok $parser->field->tag eq '006', 'field tag'; ok $parser->field->index_start == 0, 'field index_start'; ok $parser->field->index_end == 3, 'field index_end'; ok $parser->field->index_length == 4, 'field index_length'; ok $parser->field->char_start == 1, 'field char_start'; ok $parser->field->char_end == 3, 'field char_end'; ok $parser->field->char_length == 3, 'field char_length'; #checking subspecs ok scalar(grep {defined $_} @{$parser->field->subspecs}) == 2, 'field subspec count'; ok scalar(grep {defined $_} @{@{$parser->field->subspecs}[0]}) == 2, 'field subspec count2'; ok $parser->field->subspecs->[0]->[0]->operator eq '=', 'subspec 1 tag'; ok $parser->field->subspecs->[0]->[0]->left->field->tag eq 'LDR', 'subspec 1 left tag'; ok $parser->field->subspecs->[0]->[0]->left->field->char_start == 0, 'subspec 1 left char_start'; ok $parser->field->subspecs->[0]->[0]->left->field->char_end == 0, 'subspec 1 left char_end'; ok $parser->field->subspecs->[0]->[0]->left->field->char_length == 1, 'subspec 1 left char_length'; ok $parser->field->subspecs->[0]->[0]->right->raw eq 'A', 'subspec 1 right raw'; ok $parser->field->subspecs->[1]->right->raw eq 'X', 'subspec 3 right raw'; done_testing();MARC-Spec-2.0.3/t/01-char_consistent.t0000644001161400116140000000150513215154435016312 0ustar devel2devel2use Test::More; use MARC::Spec; use MARC::Spec::Field; # new Field my $field = MARC::Spec::Field->new('650'); # new MARCspec with field my $ms = MARC::Spec->new($field); $field->char_start(0); ok $ms->field->char_start == 0, 'char_start 0'; ok $ms->field->char_end eq 0, 'char_end 0'; ok $ms->field->char_length == 1, 'char_lenght -1'; ok $ms->field->to_string() eq '650[0-#]/0', 'base default got '.$ms->field->to_string(); $field->char_end(2); ok $ms->field->char_start == 0, 'char_start 0'; ok $ms->field->char_end == 2, 'char_end 2'; ok $ms->field->char_length == 3, 'char_lenght 3'; ok $ms->field->to_string() eq '650[0-#]/0-2', 'base 0-2'; $field->char_end('#'); ok $ms->field->char_length == -1, 'char_lenght -1'; ok $ms->field->to_string() eq '650[0-#]', 'base string 0-#'; done_testing();MARC-Spec-2.0.3/t/03-parser.t0000644001161400116140000000146713215154435014431 0ustar devel2devel2use Test::More; use MARC::Spec; my $parser = MARC::Spec::parse('084$a{$2=\bcl}'); # checking field ok $parser->field->tag eq '084', 'field tag'; ok $parser->field->index_start == 0, 'field index_start'; ok $parser->field->index_end eq '#', 'field index_end'; ok $parser->field->index_length == -1, 'field index_length'; ok $parser->subfields->[0]->code eq 'a', 'subfield code a'; #checking subspecs ok scalar @{$parser->subfields->[0]->subspecs} == 1, 'subbfield a subspec count'; ok $parser->subfields->[0]->subspecs->[0]->left->subfields->[0]->code eq '2', 'leftsubterm subfield tag'; ok ref $parser->subfields->[0]->subspecs->[0]->right eq 'MARC::Spec::Comparisonstring', 'rightsubterm comparisonstring'; ok $parser->subfields->[0]->subspecs->[0]->operator eq '=', 'subspec operator'; done_testing();MARC-Spec-2.0.3/t/01-to_string.t0000644001161400116140000000035713215154435015140 0ustar devel2devel2use Test::More; use MARC::Spec; my $ms = MARC::Spec::parse('246$b{$a|002}{003[0]/0=\A}'); ok $ms->to_string() eq '246[0-#]$b[0-#]{246[0-#]$b[0-#]?246[0-#]$a[0-#]|246[0-#]$b[0-#]?002[0-#]}{003[0]/0=\A}', 'to_string'; done_testing();MARC-Spec-2.0.3/t/08-parser.t0000644001161400116140000000215313215154435014427 0ustar devel2devel2use Test::More; use MARC::Spec; my $parser = MARC::Spec::parse('999$a[#]{245^1=\1}{$a=\Foo|$a=\Y}'); #checking subspecs ok scalar @{$parser->subfields->[0]->subspecs} == 2, 'subbfield a subspec count'; ok scalar @{$parser->subfields->[0]->subspecs->[1]} == 2, 'subfield a subspec count2'; ok $parser->subfields->[0]->subspecs->[0]->left->indicator->position eq 1, 'subfield a subspec indicator postion'; my $field = $parser->field; #creating more subspecs my $subspecs = [ MARC::Spec::Subspec->new( {right=> MARC::Spec::parse('245$e')} ), MARC::Spec::Subspec->new( {right => MARC::Spec::parse('245$f')} ) ]; #and adding more subspecs $field->add_subspecs($subspecs); #creating lot more subspecs my $or_subspecs = [ [ MARC::Spec::Subspec->new( {right=> MARC::Spec::parse('245$g')} ), MARC::Spec::Subspec->new( {right => MARC::Spec::parse('245$h')} ) ] ]; #and adding more subspecs $field->add_subspecs($or_subspecs); ok scalar @{$field->subspecs} == 3, 'field subspec count'; ok scalar @{$field->subspecs->[2]} == 2, 'field or subspec count'; done_testing();MARC-Spec-2.0.3/t/01-comparisonstring.t0000755001161400116140000000107313215154435016530 0ustar devel2devel2use strict; use Test::More; use Test::Exception; use MARC::Spec::Comparisonstring; use MARC::Spec::Parser; my $cmp = MARC::Spec::Comparisonstring->new('this\sis\sa\stest'); ok $cmp->raw eq 'this\sis\sa\stest', 'raw'; ok $cmp->comparable eq 'this is a test', 'comparable'; throws_ok {MARC::Spec::Comparisonstring->new('this|is|wrong');} qr/^MARCspec Comparisonstring exception.*/, 'MARCspec Comparisonstring exception'; my $parser = MARC::Spec::parse('245$a{245$a~\/}'); ok $parser->subfields->[0]->subspecs->[0]->right->raw eq '/', 'subspec right raw'; done_testing;MARC-Spec-2.0.3/t/pod.t0000644001161400116140000000020313215154435013462 0ustar devel2devel2use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok();MARC-Spec-2.0.3/t/author-pod-syntax.t0000644001161400116140000000045413215154435016316 0ustar devel2devel2#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); MARC-Spec-2.0.3/t/05-parser.t0000644001161400116140000000072713215154435014431 0ustar devel2devel2use Test::More; use MARC::Spec; my $parser = MARC::Spec::parse('245$0$a$9'); ok $parser->subfields->[0]->code eq '0', 'first subfield code'; ok $parser->subfields->[1]->code eq 'a', 'second subfield code'; ok $parser->subfields->[2]->code eq '9', 'third subfield code'; $parser = MARC::Spec::parse('245$a$0'); ok $parser->subfields->[0]->code eq 'a', 'first subfield code'; ok $parser->subfields->[1]->code eq '0', 'second subfield code'; done_testing();MARC-Spec-2.0.3/t/04-parser.t0000644001161400116140000000053613215154435014426 0ustar devel2devel2use Test::More; use MARC::Spec; my $parser = MARC::Spec::parse('084{245}'); ok $parser->field->subspecs->[0]->left->field->tag eq '084', 'field leftsubterm subfield tag'; $parser = MARC::Spec::parse('084$a{245}'); ok $parser->subfields->[0]->subspecs->[0]->left->field->tag eq '084', 'subfield leftsubterm subfield tag'; done_testing();MARC-Spec-2.0.3/t/06-parser.t0000644001161400116140000000213713215154435014427 0ustar devel2devel2use Test::More; use Test::Exception; use MARC::Spec; throws_ok { MARC::Spec::parse(['245']) } qr/SCALAR/, 'not scalar' ; throws_ok { MARC::Spec::parse('245 $a') } qr/Whitespaces are not allowed./, 'has whitespace' ; throws_ok { MARC::Spec::parse('2A') } qr/Spec must be at least/, 'only 2 chars' ; throws_ok { MARC::Spec::parse('___') } qr/For fieldtag only/, 'unallowed chars' ; throws_ok { MARC::Spec::parse('2Aa') } qr/For fieldtag only/, 'unallowed char combination' ; throws_ok { MARC::Spec::parse('245a') } qr/Detected useless data fragment/, 'useless 1' ; throws_ok { MARC::Spec::parse('245/1-2_01') } qr/Detected useless data fragment/, 'useless 2' ; throws_ok { MARC::Spec::parse('245_01/1-2') } qr/Detected useless data fragment/, 'useless 3' ; throws_ok { MARC::Spec::parse('245/1-2$a') } qr/Detected useless data fragment/, 'chapos and subfield' ; throws_ok { MARC::Spec::parse('245$A') } qr/Invalid subfield spec detected./, 'invalid subfield' ; throws_ok { MARC::Spec::parse('LDR/1-0') } qr/Ending character or index position must be equal or higher/, 'invalid charpos' ; done_testing();MARC-Spec-2.0.3/t/01-index_consistent.t0000644001161400116140000000173513215154435016511 0ustar devel2devel2use Test::More; use MARC::Spec; use MARC::Spec::Field; # new Field my $field = MARC::Spec::Field->new('650'); # new MARCspec with field my $ms = MARC::Spec->new($field); ok $ms->field->index_start == 0, 'index_start default'; ok $ms->field->index_end eq '#', 'index_end default'; ok $ms->field->index_length == -1, 'index_lenght default'; ok $ms->field->to_string() eq '650[0-#]', 'base default'; $field->index_start(0); $field->index_end(2); ok $ms->field->index_start == 0, 'index_start 0'; ok $ms->field->index_end == 2, 'index_end 2'; ok $ms->field->index_length == 3, 'index_lenght 3'; ok $ms->field->to_string() eq '650[0-2]', 'base 0-2'; $field->index_end('#'); ok $ms->field->index_length == -1, 'index_lenght -1'; ok $ms->field->to_string() eq '650[0-#]', 'base string 0-#'; $field->index_end(0); $field->index_start(3); ok $ms->field->index_end == 3, 'index_end 3'; ok $ms->field->index_length == 1, 'index_lenght 1'; done_testing();MARC-Spec-2.0.3/t/07-parser.t0000644001161400116140000000372113215154435014430 0ustar devel2devel2use Test::More; use MARC::Spec; use MARC::Spec::Subfield; my $parser = MARC::Spec::parse('006'); # checking field ok $parser->field->tag eq '006' , 'field tag'; ok $parser->field->index_start == 0 , 'field index_start'; ok $parser->field->index_end eq '#' , 'field index_end'; ok $parser->field->index_length == -1 , 'field index_length'; ok $parser->field->has_char_pos eq '' , 'field attribute has_char_pos false'; ok $parser->field->has_char_start eq '', 'field attribute has_char_start false'; ok $parser->field->has_char_end eq '' , 'field attribute has_char_end false'; $parser->field->index_start(1); ok $parser->field->index_start == 1 , 'field index_start'; ok $parser->field->index_end eq '#' , 'field index_end'; ok $parser->field->index_length == -1 , 'field index_length'; $parser->field->index_end(3); ok $parser->field->index_end == 3 , 'field index_end'; ok $parser->field->index_length == 3 , 'field index_length'; $parser->field->set_char_start_end('0-#'); ok $parser->field->char_start == 0 , 'field char_start'; ok $parser->field->char_end eq '#' , 'field char_end'; ok $parser->field->char_length == -1 , 'field char_length'; ok $parser->field->has_char_pos , 'field attribute has_char_pos true'; ok $parser->field->has_char_start , 'field attribute has_char_start true'; ok $parser->field->has_char_end , 'field attribute has_char_end true'; $parser->field->char_start(1); ok $parser->field->char_start == 1 , 'field char_start'; ok $parser->field->char_end eq '#' , 'field char_end'; ok $parser->field->char_length == -1 , 'field char_length'; $parser->field->char_end(3); ok $parser->field->char_end == 3 , 'field char_end'; ok $parser->field->char_length == 3 , 'field char_length'; my $subfield = MARC::Spec::Subfield->new('a'); $parser->add_subfield($subfield); ok $parser->subfields->[0]->code eq 'a', 'added new subfield'; done_testing();MARC-Spec-2.0.3/t/basic.t0000644001161400116140000000117313215154435013770 0ustar devel2devel2use strict; use Test::More; use MARC::Spec; use MARC::Spec::Field; use MARC::Spec::Subfield; use MARC::Spec::Comparisonstring; use MARC::Spec::Subspec; use MARC::Spec::Structure; use MARC::Spec::Parser; BEGIN { use_ok 'MARC::Spec'; use_ok 'MARC::Spec::Field'; use_ok 'MARC::Spec::Subfield'; use_ok 'MARC::Spec::Comparisonstring'; use_ok 'MARC::Spec::Subspec'; use_ok 'MARC::Spec::Parser'; } require_ok 'MARC::Spec'; require_ok 'MARC::Spec::Field'; require_ok 'MARC::Spec::Subfield'; require_ok 'MARC::Spec::Comparisonstring'; require_ok 'MARC::Spec::Subspec'; require_ok 'MARC::Spec::Parser'; done_testing; MARC-Spec-2.0.3/t/10-parser.t0000644001161400116140000000061113215154435014415 0ustar devel2devel2use Test::More; use MARC::Spec::Parser; my $parser = MARC::Spec::parse('006$a{^1}'); ok $parser->subfields->[0]->subspecs->[0]->right->indicator->position eq '1', 'subspec indicator position abbreviation2'; $parser = MARC::Spec::parse('006^2{^1}'); ok $parser->indicator->subspecs->[0]->right->indicator->position eq '1', 'subspec indicator position abbreviation3'; done_testing();MARC-Spec-2.0.3/t/02-parser.t0000755001161400116140000000133613215154435014426 0ustar devel2devel2use Test::More; use MARC::Spec; my $parser = MARC::Spec::parse('...$a-z{LDR/0=\A|LDR/0=\X}{LDR/1!=\X}$$/1-#'); # checking field ok $parser->field->tag eq '...', 'field tag'; ok $parser->field->index_start == 0, 'field index_start'; ok $parser->field->index_end eq '#', 'field index_end'; ok $parser->field->index_length == -1, 'field index_length'; ok $parser->subfields->[0]->code eq 'a', 'subfield code a'; ok $parser->subfields->[2]->code eq 'c', 'subfield code a'; ok scalar @{$parser->subfields} == 27, 'subfields length'; #checking subspecs ok scalar @{$parser->subfields->[0]->subspecs} == 2, 'subbfield a subspec count'; ok scalar @{$parser->subfields->[0]->subspecs->[0]} == 2, 'subfield a subspec count2'; done_testing();MARC-Spec-2.0.3/t/01-marcspec.t0000644001161400116140000000466013215154435014726 0ustar devel2devel2use Test::More; use MARC::Spec; use MARC::Spec::Field; use MARC::Spec::Indicator; use MARC::Spec::Subfield; use MARC::Spec::Comparisonstring; use MARC::Spec::Subspec; # new Comparisonstring my $cmp = MARC::Spec::Comparisonstring->new('test'); # new Subspec my $subspec = MARC::Spec::Subspec->new; # Comparisonstring is right subterm $subspec->right($cmp); # Operator is equal $subspec->operator('='); # Parsed MARCspec as right subterm $subspec->left(MARC::Spec::parse('245$b')); # new Field my $field = MARC::Spec::Field->new('245'); # Field attributes $field->index_start(1); $field->index_end(3); # adding one subspec $field->add_subspec($subspec); # creating more subspecs my $subspecs = [ MARC::Spec::Subspec->new( {right=> MARC::Spec::parse('245$e')} ), MARC::Spec::Subspec->new( {right => MARC::Spec::parse('245$f')} ) ]; # and adding more subspecs $field->add_subspecs($subspecs); # creating lot more subspecs my $or_subspecs = [ [ MARC::Spec::Subspec->new( {right=> MARC::Spec::parse('245$g')} ), MARC::Spec::Subspec->new( {right => MARC::Spec::parse('245$h')} ) ] ]; # and adding more subspecs $field->add_subspecs($or_subspecs); # new Subfield my $subfield_a = MARC::Spec::Subfield->new('a'); my $subfield_c = MARC::Spec::Subfield->new('c'); my $subfield_d = MARC::Spec::Subfield->new('d'); # new MARCspec with field my $ms = MARC::Spec->new($field); # add subfield a $ms->add_subfield($subfield_a); # add other subfields $ms->add_subfields([$subfield_c, $subfield_d]); ok $ms->field->tag eq '245', 'field tag'; ok $ms->field->index_start == 1, 'index start'; ok $ms->field->index_end == 3, 'index end'; ok scalar @{$ms->field->subspecs} == 4, 'number of AND subspecs'; ok scalar @{$ms->field->subspecs->[3]} == 2, 'number of OR subspecs'; ok ref $ms->field->subspecs->[0]->right eq 'MARC::Spec::Comparisonstring', 'right subterm Comparisonstring'; ok scalar @{$ms->subfields} == 3, 'number of subfields'; my $indicator = MARC::Spec::Indicator->new('2'); # and adding more subspecs $indicator->add_subspecs($subspecs); my $field2 = MARC::Spec::Field->new('245'); my $ms2 = MARC::Spec->new($field2); $ms2->indicator($indicator); ok $ms2->indicator->position eq '2', 'indicator position'; ok $ms2->indicator->base eq '^2', 'indicator position'; ok scalar @{$ms2->indicator->subspecs} == 2, 'indicator subspecs'; done_testing();MARC-Spec-2.0.3/META.json0000644001161400116140000000365713215154435013711 0ustar devel2devel2{ "abstract" : "A MARCspec parser and builder", "author" : [ "Carsten Klee C<< >>" ], "dynamic_config" : 0, "generated_by" : "Dist::Milla version v1.0.18, Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "MARC-Spec", "no_index" : { "directory" : [ "eg", "examples", "inc", "share", "t", "xt" ] }, "prereqs" : { "configure" : { "requires" : { "Module::Build::Tiny" : "0.034" } }, "develop" : { "requires" : { "Dist::Milla" : "v1.0.18", "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "Carp" : "1.38", "Const::Fast" : "0.014", "Moo" : "1.0", "namespace::clean" : "0.27", "perl" : "v5.10.0" } }, "test" : { "requires" : { "Test::Exception" : "0", "Test::More" : "0", "Test::Pod" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/MARCspec/MARC-Spec/issues" }, "homepage" : "https://github.com/MARCspec/MARC-Spec", "repository" : { "type" : "git", "url" : "https://github.com/MARCspec/MARC-Spec.git", "web" : "https://github.com/MARCspec/MARC-Spec" } }, "version" : "2.0.3", "x_contributors" : [ "Carsten Klee ", "Carsten Klee ", "Mirko Tietgen ", "Mohammad S Anwar " ], "x_serialization_backend" : "Cpanel::JSON::XS version 3.0233" } MARC-Spec-2.0.3/LICENSE0000644001161400116140000004377313215154435013300 0ustar devel2devel2This software is copyright (c) 2016 by Carsten Klee C<< >>. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2016 by Carsten Klee C<< >>. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2016 by Carsten Klee C<< >>. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End MARC-Spec-2.0.3/META.yml0000644001161400116140000000214313215154435013526 0ustar devel2devel2--- abstract: 'A MARCspec parser and builder' author: - 'Carsten Klee C<< >>' build_requires: Test::Exception: '0' Test::More: '0' Test::Pod: '0' configure_requires: Module::Build::Tiny: '0.034' dynamic_config: 0 generated_by: 'Dist::Milla version v1.0.18, Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: MARC-Spec no_index: directory: - eg - examples - inc - share - t - xt requires: Carp: '1.38' Const::Fast: '0.014' Moo: '1.0' namespace::clean: '0.27' perl: v5.10.0 resources: bugtracker: https://github.com/MARCspec/MARC-Spec/issues homepage: https://github.com/MARCspec/MARC-Spec repository: https://github.com/MARCspec/MARC-Spec.git version: 2.0.3 x_contributors: - 'Carsten Klee ' - 'Carsten Klee ' - 'Mirko Tietgen ' - 'Mohammad S Anwar ' x_serialization_backend: 'YAML::Tiny version 1.70' MARC-Spec-2.0.3/dist.ini0000644001161400116140000000001113215154435013711 0ustar devel2devel2[@Milla] MARC-Spec-2.0.3/cpanfile0000644001161400116140000000037513215154435013766 0ustar devel2devel2requires 'perl', 'v5.10.0'; requires 'Moo', '1.0'; requires 'Carp', '1.38'; requires 'Const::Fast', '0.014'; requires 'namespace::clean', '0.27'; on test => sub { requires 'Test::More'; requires 'Test::Exception'; requires 'Test::Pod'; }; MARC-Spec-2.0.3/Build.PL0000644001161400116140000000025613215154435013554 0ustar devel2devel2# This Build.PL for MARC-Spec was generated by Dist::Zilla::Plugin::ModuleBuildTiny 0.015. use strict; use warnings; use v5.10.0; use Module::Build::Tiny 0.034; Build_PL(); MARC-Spec-2.0.3/README0000644001161400116140000001051713215154435013141 0ustar devel2devel2NAME MARC::Spec - A MARCspec parser and builder SYNOPSIS use MARC::Spec; # Parsing MARCspec from a string my $ms = MARC::Spec::parse('246[0-1]$f{245$h~\[microform\]|245$h~\microfilm}'); # Structure say ref $ms; # MARC::Spec say ref $ms->field; # MARC::Spec::Field say ref $ms->subfields; # ARRAY say ref $ms->subfields->[0]; # MARC::Spec::Subfield say ref $ms->subfields->[0]->subspecs; # ARRAY say ref $ms->subfields->[0]->subspecs->[0]; # ARRAY say ref $ms->subfields->[0]->subspecs->[0]->[1]; # MARC::Spec::Subspec say ref $ms->subfields->[0]->subspecs->[0]->[1]->left; # MARC::Spec say ref $ms->subfields->[0]->subspecs->[0]->[1]->right; # MARC::Spec::Comparisonstring # Access to attributes say $ms->field->base; # 246[0-1] say $ms->field->tag; # 246 say $ms->field->index_start; # 0 say $ms->field->index_end; # 1 say $ms->field->index_length; # 2 say $ms->subfields->[0]->base; # 'f[0-#]' say $ms->subfields->[0]->code; # 'f' say $ms->subfields->[0]->index_start; # 0 say $ms->subfields->[0]->index_end; # '#' say $ms->subfields->[0]->subspecs->[0]->[0]->subterms; # '245$h~\[microform\]' say $ms->subfields->[0]->subspecs->[0]->[0]->left->field->tag; # 245 say $ms->subfields->[0]->subspecs->[0]->[0]->left->field->index_length; # -1 say $ms->subfields->[0]->subspecs->[0]->[0]->left->subfields->[0]->code; # 'h' say $ms->subfields->[0]->subspecs->[0]->[0]->right->comparable; # '[microform]' say $ms->subfields->[0]->subspecs->[0]->[1]->right->comparable; # 'microfilm' # creating MARCspec from scratch my $field = MARC::Spec::Field->new('245'); my $subfield = MARC::Spec::Subfield->new('a'); my $spec = MARC::Spec->new($field); $spec->add_subfield($subfield); DESCRIPTION MARC::Spec is a MARCspec - A common MARC record path language parser and builder. FUNCTIONS parse(Str) Parses a MARCspec as string and returns an instance of MARC::Spec. METHODS new(MARC::Spec::Field) Create a new MARC::Spec instance. Parameter must be an instance of MARC::Spec::Field. add_subfield(MARC::Spec::Subfield) Appends a subfield to the array of the attribute subfields. Parameter must be an instance of MARC::Spec::Subfield. add_subfields(ArrayRef[MARC::Spec::Subfield]) Appends subfields to the array of the attribute subfields. Parameter must be an ArrayRef and elements must be instances of MARC::Spec::Subfield. PREDICATES has_subfields Returns true if attribute subfields has an value and false otherwise. has_indicator Returns true if attribute indicator has an value and false otherwise. ATTRIBUTES field Obligatory. Attribute field is an instance of MARC::Spec::Field. subfields If defined, subfields is an array of instances of MARC::Spec::Subfield. indicator If defined, indicator is an instance of MARC::Spec::Indicator. AUTHOR Carsten Klee CONTRIBUTORS * Johann Rolschewski, COPYRIGHT AND LICENSE This software is copyright (c) 2016 by Carsten Klee. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. BUGS Please report any bugs to https://github.com/MARCspec/MARC-Spec/issues SEE ALSO * MARC::Spec::Field * MARC::Spec::Subfield * MARC::Spec::Indicator * MARC::Spec::Subspec * MARC::Spec::Structure * MARC::Spec::Comparisonstring * MARC::Spec::Parser MARC-Spec-2.0.3/MANIFEST0000644001161400116140000000120613215154435013405 0ustar devel2devel2# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.010. Build.PL Changes LICENSE MANIFEST META.json META.yml README cpanfile dist.ini lib/MARC/Spec.pm lib/MARC/Spec/Comparisonstring.pm lib/MARC/Spec/Field.pm lib/MARC/Spec/Indicator.pm lib/MARC/Spec/Parser.pm lib/MARC/Spec/Structure.pm lib/MARC/Spec/Subfield.pm lib/MARC/Spec/Subspec.pm t/01-char_consistent.t t/01-comparisonstring.t t/01-index_consistent.t t/01-marcspec.t t/01-parser.t t/01-to_string.t t/02-parser.t t/03-parser.t t/04-parser.t t/05-parser.t t/06-parser.t t/07-parser.t t/08-parser.t t/09-parser.t t/10-parser.t t/author-pod-syntax.t t/basic.t t/pod.t MARC-Spec-2.0.3/Changes0000644001161400116140000000225313215154435013552 0ustar devel2devel2Revision history for MARC-Spec-Parser 2.0.3 2017-12-16 09:28:09 CET - fixed bug indictor subspec abbreviation 2.0.2 2017-12-13 07:36:04 CET - minor: adjusted POD - Tidied up abstract in pod as reported by CPANTS. from manwar 2.0.1 2017-12-12 15:33:38 CET - removed DPP dependencyy in test 2.0.0 2017-12-12 13:46:21 CET - new class Indicator (conforms to MARCspec 0.16beta) 1.0.0 2017-05-11 13:43:22 CEST - parse is not an object method 0.1.4 2017-04-06 08:11:51 CEST - Bug fixing: leave or subspecs nested when adding 0.1.3 2017-03-24 08:11:47 CET - Fix spelling error in pod from dr0jf 0.1.2 2017-03-06 12:01:05 CET - Fix POD NAME structure 0.1.1 2017-03-01 06:42:01 CET - equality test on mixed scalar 0.1.0 2017-02-20 12:01:40 CET - new has_* attributes - new travis.yml 0.0.4 2017-02-17 07:08:15 CET - typos in POD - update of base attribute of Structure 0.0.3 2016-07-05 12:47:30 CEST - precompiled regex - require some modules 0.0.2 2016-07-01 10:55:03 CEST - deleted strictures 0.0.1 2016-07-01 10:15:32 CEST - Initial release MARC-Spec-2.0.3/lib/0000755001161400116140000000000013215154435013023 5ustar devel2devel2MARC-Spec-2.0.3/lib/MARC/0000755001161400116140000000000013215154435013545 5ustar devel2devel2MARC-Spec-2.0.3/lib/MARC/Spec.pm0000644001161400116140000001501213215154435014774 0ustar devel2devel2package MARC::Spec; use Carp qw(croak); use Moo; use MARC::Spec::Parser; use namespace::clean; our $VERSION = '2.0.3'; has field => ( is => 'rw', isa => sub { croak('Field is not an instance of MARC::Spec::Field') if(ref $_[0] ne 'MARC::Spec::Field') }, required => 1 ); has subfields => ( is => 'rwp', isa => sub { croak('Subfield is not an instance of MARC::Spec::Subfield.') if(grep {ref $_ ne 'MARC::Spec::Subfield'} @{$_[0]}) }, predicate => 1 ); has indicator => ( is => 'rw', isa => sub { croak('Indicator is not an instance of MARC::Spec::Indicator.') if(ref $_[0] ne 'MARC::Spec::Indicator') }, predicate => 1 ); sub BUILDARGS { my ($class, @args) = @_; if (@args % 2 == 1) { unshift @args, "field" } return { @args }; } sub add_subfield { my ($self, $subfield) = @_; if(!$self->has_subfields) { $self->_set_subfields([$subfield]); } else { my @subfields = ( @{$self->subfields}, $subfield ); $self->_set_subfields( \@subfields ); } } sub add_subfields { my ($self, $subfields) = @_; if (ref $subfields ne 'ARRAY') { croak('Subfields is not an ARRAYRef!') } if(!$self->has_subfields) { $self->_set_subfields($subfields); } else { my @merged = ( @{$self->subfields}, @{$subfields} ); $self->_set_subfields( \@merged ) } } sub parse { my ($spec) = @_; my $parser = MARC::Spec::Parser->new($spec); return $parser->marcspec; } sub to_string { my ($self) = @_; my $string = $self->field->to_string(); if($self->has_subfields) { foreach my $sf (@{$self->subfields}) { $string .= $sf->to_string() } } elsif($self->has_indicator) { $string .= $self->indicator->to_string(); } return $string; } 1; __END__ =encoding utf-8 =head1 NAME MARC::Spec - A MARCspec parser and builder =head1 SYNOPSIS use MARC::Spec; # Parsing MARCspec from a string my $ms = MARC::Spec::parse('246[0-1]$f{245$h~\[microform\]|245$h~\microfilm}'); # Structure say ref $ms; # MARC::Spec say ref $ms->field; # MARC::Spec::Field say ref $ms->subfields; # ARRAY say ref $ms->subfields->[0]; # MARC::Spec::Subfield say ref $ms->subfields->[0]->subspecs; # ARRAY say ref $ms->subfields->[0]->subspecs->[0]; # ARRAY say ref $ms->subfields->[0]->subspecs->[0]->[1]; # MARC::Spec::Subspec say ref $ms->subfields->[0]->subspecs->[0]->[1]->left; # MARC::Spec say ref $ms->subfields->[0]->subspecs->[0]->[1]->right; # MARC::Spec::Comparisonstring # Access to attributes say $ms->field->base; # 246[0-1] say $ms->field->tag; # 246 say $ms->field->index_start; # 0 say $ms->field->index_end; # 1 say $ms->field->index_length; # 2 say $ms->subfields->[0]->base; # 'f[0-#]' say $ms->subfields->[0]->code; # 'f' say $ms->subfields->[0]->index_start; # 0 say $ms->subfields->[0]->index_end; # '#' say $ms->subfields->[0]->subspecs->[0]->[0]->subterms; # '245$h~\[microform\]' say $ms->subfields->[0]->subspecs->[0]->[0]->left->field->tag; # 245 say $ms->subfields->[0]->subspecs->[0]->[0]->left->field->index_length; # -1 say $ms->subfields->[0]->subspecs->[0]->[0]->left->subfields->[0]->code; # 'h' say $ms->subfields->[0]->subspecs->[0]->[0]->right->comparable; # '[microform]' say $ms->subfields->[0]->subspecs->[0]->[1]->right->comparable; # 'microfilm' # creating MARCspec from scratch my $field = MARC::Spec::Field->new('245'); my $subfield = MARC::Spec::Subfield->new('a'); my $spec = MARC::Spec->new($field); $spec->add_subfield($subfield); =head1 DESCRIPTION MARC::Spec is a L parser and builder. =head1 FUNCTIONS =head2 parse(Str) Parses a MARCspec as string and returns an instance of MARC::Spec. =head1 METHODS =head2 new(MARC::Spec::Field) Create a new MARC::Spec instance. Parameter must be an instance of L. =head2 add_subfield(MARC::Spec::Subfield) Appends a subfield to the array of the attribute subfields. Parameter must be an instance of L. =head2 add_subfields(ArrayRef[MARC::Spec::Subfield]) Appends subfields to the array of the attribute subfields. Parameter must be an ArrayRef and elements must be instances of L. =head1 PREDICATES =head2 has_subfields Returns true if attribute subfields has an value and false otherwise. =head2 has_indicator Returns true if attribute indicator has an value and false otherwise. =head1 ATTRIBUTES =head2 field Obligatory. Attribute field is an instance of L. =head2 subfields If defined, subfields is an array of instances of L. =head2 indicator If defined, indicator is an instance of L. =head1 AUTHOR Carsten Klee C<< >> =head1 CONTRIBUTORS =over =item * Johann Rolschewski, C<< >> =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2016 by Carsten Klee. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 BUGS Please report any bugs to L =head1 SEE ALSO =over =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =cut MARC-Spec-2.0.3/lib/MARC/Spec/0000755001161400116140000000000013215154435014437 5ustar devel2devel2MARC-Spec-2.0.3/lib/MARC/Spec/Subspec.pm0000755001161400116140000000543413215154435016412 0ustar devel2devel2package MARC::Spec::Subspec; use Moo; use namespace::clean; our $VERSION = '2.0.3'; has left => ( is => 'rw', isa => sub { croak ('Left subterm is not an instance of MARC::Spec or MARC::Spec::Comparisonstring.') unless(ref $_[0] eq 'MARC::Spec' or ref $_[0] eq 'MARC::Spec::Comparisonstring') } ); has right => ( is => 'rw', isa => sub { croak ('Right subterm is not an instance of MARC::Spec or MARC::Spec::Comparisonstring.') unless(ref $_[0] eq 'MARC::Spec' or ref $_[0] eq 'MARC::Spec::Comparisonstring') } ); has operator => ( is => 'rw', default => sub { "?" } ); sub to_string { my ($self) = @_; my $string = $self->left->to_string().$self->operator.$self->right->to_string(); return $string; } 1; __END__ =encoding utf-8 =head1 NAME MARC::Spec::Subspec - subspec specification =head1 SYNOPSIS use MARC::Spec; use MARC::Spec::Subspec; use MARC::Spec::Comparisonstring; # create an empty subspec my $subspec = MARC::Spec::Subspec->new; # create the subterms my $ms = MARC::Spec::parse('245$a')'; my $cmp = MARC::Spec::Comparisonstring->new('Perl'); # add subterms to subspec $subspec->left($ms); $subspec->right($cmp); $subspec->operator('='); say $subspec->subterms; # '245$a=\Perl' =head1 DESCRIPTION MARC::Spec::Subspec is the subspec specification of a L. See L for further details on the syntax. =head1 METHODS =head2 new Create a new MARC::Spec::Subspec instance. =head2 to_string Returns the spec as a string. =head1 ATTRIBUTES =head2 left Obligatory. The left subterm: a MARCspec as a string. =head2 right Obligatory. The right subterm: a MARCspec as a string. =head2 operator One of "=", "!=", "~", "!~", "!", or "?". Default is "?". =head1 AUTHOR Carsten Klee C<< >> =head1 CONTRIBUTORS =over =item * Johann Rolschewski, C<< >> =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2016 by Carsten Klee. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 BUGS Please report any bugs to L =head1 SEE ALSO =over =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =cut MARC-Spec-2.0.3/lib/MARC/Spec/Structure.pm0000755001161400116140000002312613215154435017004 0ustar devel2devel2package MARC::Spec::Structure; use Moo; use Const::Fast; use Carp qw(croak); use namespace::clean; our $VERSION = '2.0.3'; const my $NO_LENGTH => -1; const my $LAST => '#'; has base => ( is => 'rwp', lazy => 1, builder => '_base' ); sub _base { my ($self) = @_; my $base = ($self->can('tag')) ? $self->tag : '$'.$self->code; $base .= '['.$self->index_start; if($self->index_start ne $self->index_end) { $base .= '-'.$self->index_end } $base .= ']'; if(defined $self->char_start) { my $char_start = $self->char_start; my $char_end = $self->char_end; unless($char_start eq '0' && $char_end eq '#') { $base .= '/'.$char_start; if($char_end ne $char_start) { $base .= '-'.$char_end } } } return $base; } has index_start => ( is => 'rw', default => sub {0}, trigger => sub { my ($self, $index_start) = @_; if ($LAST ne $self->index_end && $LAST ne $index_start && $self->index_end < $index_start) { $self->index_end($index_start); } else { $self->_set_base( $self->_base() ); } $self->_set_index_length( _calculate_length($index_start, $self->index_end) ) } ); has index_end => ( is => 'rw', default => sub {$LAST}, trigger => sub { my ($self, $index_end) = @_; if ($LAST ne $self->index_start && $LAST ne $index_end && $self->index_start > $index_end) { $self->index_start($index_end); } else { $self->_set_base( $self->_base() ); } $self->_set_index_length( _calculate_length($self->index_start, $index_end) ) } ); has index_length => ( is => 'rwp', default => sub {$NO_LENGTH} ); has char_start => ( is => 'rw', trigger => sub { my ($self, $char_start) = @_; if(!defined $self->char_end) { $self->char_end($char_start) } $self->_set_char_pos($self->char_start.'-'.$self->char_end); $self->_set_char_length( _calculate_length($char_start, $self->char_end) ); $self->_set_base( $self->_base() ) }, predicate => 1 ); has char_end => ( is => 'rw', trigger => sub { my ($self, $char_end) = @_; if(!defined $self->char_start) { $self->char_start($char_end) } $self->_set_char_pos($self->char_start.'-'.$self->char_end); $self->_set_char_length( _calculate_length($self->char_start, $char_end) ); $self->_set_base( $self->_base() ) }, predicate => 1 ); has char_pos => ( is => 'rwp', predicate => 1 ); has char_length => ( is => 'rwp', lazy => 1, builder => sub { my ($self) = @_; return _calculate_length($self->char_start, $self->char_end) } ); has subspecs => ( is => 'rwp', isa => sub { foreach my $and (@{$_[0]}) { if(ref $and eq 'ARRAY') { foreach my $or (@{$and}) { croak('Subspec is not an instance of MARC::Spec::Subspec.') if(ref $or ne 'MARC::Spec::Subspec') } } else { croak('Subspec is not an instance of MARC::Spec::Subspec.') if(ref $and ne 'MARC::Spec::Subspec') } } }, predicate => 1 ); sub set_index_start_end { my ($self, $indizes) = @_; my @pos = _validate_pos($indizes); $self->index_start($pos[0]); defined $pos[1] ? $self->index_end($pos[1]) : $self->index_end($pos[0]) } sub set_char_start_end { my ($self, $charpos) = @_; my @pos = _validate_pos($charpos); $self->char_start($pos[0]); defined $pos[1] ? $self->char_end($pos[1]) : $self->char_end($pos[0]) } sub add_subspec { my ($self, $subspec) = @_; if(!$self->has_subspecs) { $self->_set_subspecs([$subspec]); } else { my @subspecs = ( @{$self->subspecs}, $subspec ); $self->_set_subspecs( \@subspecs ) } } sub add_subspecs { my ($self, $subspecs) = @_; if (ref $subspecs ne 'ARRAY') { croak('Subspecs is not an ARRAYRef!') } if(!$self->has_subspecs) { $self->_set_subspecs($subspecs) } else { my @merged = @{$self->subspecs}; push @merged, @{$subspecs}; $self->_set_subspecs( \@merged ) } } sub to_string { my ($self) = @_; my $string = $self->base; if($self->has_subspecs) { my @outer = (); foreach my $ss (@{$self->subspecs}) { if(ref $ss eq 'ARRAY') { my $inner = join '|', map {$_->to_string()} @{$ss}; push @outer, $inner; } else { push @outer, $ss->to_string(); } } my $joined = join '}{', @outer; $string .= '{'. $joined .'}'; } return $string; } sub _calculate_length { my ($start, $end) = @_; # start eq end if ($start eq $end) { return 1 } # start = #, end != # if($LAST eq $start && $LAST ne $end) { return $end + 1 } # start != #, end = # if($LAST ne $start && $LAST eq $end) { return $NO_LENGTH } my $length = $end - $start + 1; if(1 > $length) { _throw("Ending character or index position must be equal or higher than starting character or index position.", "$start-$end"); } return $length; } sub _validate_pos { my ($charpos) = @_; if($charpos =~ /[^0-9\-#]/s) { _throw("Assuming index or character position or range. Only digits, the character '#' and one '-' is allowed.", $charpos); } # something like 123- is not valid if('-' eq substr $charpos, -1) { _throw("Assuming index or character range. At least two digits or the character '#' must be present." ,$charpos); } # something like -123 is not valid if('-' eq substr $charpos, 0, 1) { _throw("Assuming index or character position or range. First character must not be '-'.", $charpos); } my @pos = split /\-/, $charpos, 2; # set end pos to start pos if no end pos if(!defined $pos[1]) { push (@pos, $pos[0]) } return @pos; } sub _throw { my ($message, $hint) = @_; croak 'MARCspec Parser exception. '.$message.' Tried to parse: '.$hint; } 1; __END__ =encoding utf-8 =head1 NAME MARC::Spec::Structure - base class =head1 SYNOPSIS use MARC::Spec::Field; # create a new field my $field = MARC::Spec::Field->new('246'); # field does inherit all attributes, predicates and methods say $field->DOES('MARC::Spec::Structure'); # 1 =head1 DESCRIPTION Is the base class for L and L. =head1 METHODS =head2 set_index_start_end (Str) Sets MARC::Spec::Structure::$index_start and MARC::Spec::Structure::$index_end from an index position or range. =head2 set_char_start_end (Str) Sets MARC::Spec::Structure::$char_start and MARC::Spec::Structure::$char_end from an character position or range. =head2 add_subspec(MARC::Spec::Subspec) Appends a subspec to the array of the attribute subspecs. Parameter must be an instance of L. =head2 add_subspecs(ArrayRef[MARC::Spec::Subspec]) Appends subspecs to the array of the attribute subspecs. Parameter must be an ArrayRef and elements must be instances of L. =head1 PREDICATES =head2 has_char_start True if attribute char_start has an value and false otherwise. =head2 has_char_end True if attribute char_end has an value and false otherwise. =head2 has_char_pos True if attribute char_pos has an value and false otherwise. =head2 has_subspecs Returns true if attribute subspecs has an value and false otherwise. =head1 ATTRIBUTES =head2 base Obligatory. Scalar. Normalized MARCspec without Subspecs. =head2 char_start If defined, the beginning character position of a character position or range. =head2 char_end If defined, the ending character position of a character position or range. Only present if MARC::Spec::Structure::$char_start is defined. =head2 char_length The difference of MARC::Spec::Structure::$char_start and MARC::Spec::Structure::$char_end if both are numeric (or else -1). Only present if MARC::Spec::Structure::$char_start is defined. =head2 char_pos If defined, the character position or range. Only present if MARC::Spec::Structure::$char_start is defined. =head2 index_start Obligatory. The beginning index of field repetitions. Maybe a positiv integer or the character '#'. Default is 0. =head2 index_end Obligatory. The ending index of field repetitions. Maybe a positiv integer or the character '#'. Default is '#'. =head2 index_length Obligatory. The difference of MARC::Spec::Structure::$index_start and MARC::Spec::Structure::$index_end if both are numeric. Default is -1. =head1 AUTHOR Carsten Klee C<< >> =head1 CONTRIBUTORS =over =item * Johann Rolschewski, C<< >> =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2016 by Carsten Klee. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 BUGS Please report any bugs to L =head1 SEE ALSO =over =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =cut MARC-Spec-2.0.3/lib/MARC/Spec/Comparisonstring.pm0000755001161400116140000000503513215154435020344 0ustar devel2devel2package MARC::Spec::Comparisonstring; use Carp qw(croak); use Moo; use namespace::clean; our $VERSION = '2.0.3'; has raw => ( is => 'rwp', required => 1 ); has comparable => ( is => 'rwp' ); sub BUILDARGS { my ( $class, @args ) = @_; unshift @args, "raw" if @args % 2 == 1; return { @args }; } sub BUILD { my ($self, $args) = @_; # char of list ${}!=~?|\s must be escaped if not at index 0* croak "MARCspec Comparisonstring exception. Unescaped character detected. Tried to parse: ".$self->raw unless($self->raw =~ /^(.(?:[^\$\{\}\!\=\~\?\|\s]|(?<=\\\\)[\$\{\}\!\=\~\?\|])*)$/s); my $comparable = $self->raw; my $replace = ' '; $comparable =~ s{\\s}{$replace}g; $self->_set_comparable($comparable); return; } sub to_string { my ($self) = @_; my $string = '\\'.$self->raw; return $string; } 1; __END__ =encoding utf-8 =head1 NAME MARC::Spec::Comparisonstring - comparison string specification =head1 SYNOPSIS use MARC::Spec; my $ms = MARC::Spec->new('245{$a~\marc}); say ref $ms->field->subspecs->[0]->rightSubTerm; # MARC::Spec::Comparisonstring =head1 DESCRIPTION MARC::Spec::Comparisonstring is the comparison string specification of a L. See L for further details on the syntax. =head1 METHODS =head2 new Create a new MARC::Spec::Comparisonstring instance. =head2 to_string Returns the spec as a string. =head1 ATTRIBUTES =head2 raw Obligatory. The raw comparison string with escaped characters. =head2 comparable Obligatory. The comparison string without the escaping "\". =head1 AUTHOR Carsten Klee C<< >> =head1 CONTRIBUTORS =over =item * Johann Rolschewski, C<< >> =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2016 by Carsten Klee. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 BUGS Please report any bugs to L =head1 SEE ALSO =over =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =cut MARC-Spec-2.0.3/lib/MARC/Spec/Parser.pm0000644001161400116140000002514413215154435016237 0ustar devel2devel2package MARC::Spec::Parser; use Carp qw(croak); use Const::Fast; use Moo; use MARC::Spec; use MARC::Spec::Field; require MARC::Spec::Subfield; require MARC::Spec::Indicator; require MARC::Spec::Comparisonstring; require MARC::Spec::Subspec; use namespace::clean; our $VERSION = '2.0.3'; has spec => ( is => 'rw', required => 1 ); has marcspec => ( is => 'rwp' ); const my $FIELDTAG => q{(?(?:[a-z0-9\.]{3,3}|[A-Z0-9\.]{3,3}|[0-9\.]{3,3}))}; const my $POSITIONORRANGE => q{(?:(?:(?:[0-9]+|#)\-(?:[0-9]+|#))|(?:[0-9]+|#))}; const my $INDEX => qq{(?:\\[(?$POSITIONORRANGE)\\])?}; const my $CHARPOS => qq{(?:\\/(?$POSITIONORRANGE))?}; const my $INDICATORPOS => q{(?:\^(?[12]))}; const my $SUBSPECS => q{(?(?:\\{.+?(? q{(?\$.+)}; const my $FIELD => qq{(?$FIELDTAG$INDEX)}; const my $MARCSPEC => qr/^(?$FIELD(?:$SUBFIELDS|(?:$INDICATORPOS|$CHARPOS)$SUBSPECS))/s; const my $SUBFIELDRANGE => q{(?(?:[0-9a-z]\-[0-9a-z]))}; const my $SUBFIELDTAG => q{(?[\!-\?\[-\\{\\}-~])}; const my $SUBFIELD => qr/(?\$(?:$SUBFIELDRANGE|$SUBFIELDTAG)$INDEX$CHARPOS$SUBSPECS)/s; const my $LEFTSUBTERM => q{^(?(?:\\\(?:(?<=\\\)[\!\=\~\?]|[^\!\=\~\?])+)|(?:(?<=\$)[\!\=\~\?]|[^\!\=\~\?])+)?}; const my $OPERATOR => q{(?\!\=|\!\~|\=|\~|\!|\?)}; const my $SUBTERMS => qq{(?:$LEFTSUBTERM$OPERATOR)?(?.+)}.q{$}; const my $SUBSPEC => qr/(?:\{(.+?)\})/s; const my $UNESCAPED => qr/(? 3; const my $MIN_LENGTH_SUBFIELD => 2; const my $NO_LENGTH => -1; const my $ERROR => 'Only one of characterSpec, subfieldSpec or indicatorSpec is allowed.'; my %cache; sub BUILDARGS { my ($class, @args) = @_; if (@args % 2 == 1) { unshift @args, "spec" } return { @args }; } sub BUILD { my ($self) = @_; my ($indicator, $subspecs, $field, $ms); _do_checks($self->spec, $MIN_LENGTH_FIELD); $self->spec =~ $MARCSPEC; %{$self->{_parsed}} = %+; if(!$self->{_parsed}->{tag}) { _throw("For fieldtag only '.', digits and lowercase alphabetic or digits and upper case alphabetics characters are allowed.", $self->spec); } if( length $self->{_parsed}->{marcspec} != length $self->spec ) { _throw('Detected useless data fragment or invalid field spec.', $self->spec); } # create a new Field $field = MARC::Spec::Field->new($self->{_parsed}->{tag}); if(defined $self->{_parsed}->{charpos}) { if(defined $self->{_parsed}->{subfields}) { _throw($ERROR, $self->spec); } $field->set_char_start_end($self->{_parsed}->{charpos}); } if(defined $self->{_parsed}->{index}) { $field->set_index_start_end($self->{_parsed}->{index}); } $self->{field_base} = $field->base; $ms = MARC::Spec->new($field); if(defined $self->{_parsed}->{indicatorpos}) { if(defined $self->{_parsed}->{charpos}) { _throw($ERROR, $self->spec); } $indicator = MARC::Spec::Indicator->new($self->{_parsed}->{indicatorpos}); $ms->indicator($indicator); } elsif($self->{_parsed}->{subfields}) { if(defined $self->{_parsed}->{indicatorpos}) { _throw($ERROR, $self->spec); } my $subfields = $self->_match_subfields(); $ms->add_subfields($subfields); } if($self->{_parsed}->{subspecs}) { $subspecs = $self->_match_subspecs($self->{_parsed}->{subspecs}); if(defined $indicator) { $self->_populate_subspecs($indicator, $subspecs, [$field->base, $indicator->base]); } else { $self->_populate_subspecs($field, $subspecs, [$field->base]); } } $self->_set_marcspec($ms); } sub _populate_subspecs { my ($self, $spec, $subspecs, $base) = @_; foreach my $subspec (@{$subspecs}) { # check if array length is above 1 if(1 < scalar @{$subspec}) { # alternatives to array (OR) my @or = (); foreach my $or_subspec (@{$subspec}) { push @or, $self->_match_subterms($or_subspec, $base); } $spec->add_subspecs([\@or]); } else { $spec->add_subspec( $self->_match_subterms($subspec->[0], $base ) ); } } } sub _match_subfields { my ($self) = @_; _do_checks($self->{_parsed}->{subfields}, $MIN_LENGTH_SUBFIELD); my $subfields = []; my $i = 0; while($self->{_parsed}->{subfields} =~ /$SUBFIELD/g) { if(defined $+{range}) { my $from = substr $+{range},0,1; my $to = substr $+{range},2,1; for my $code ( $from .. $to) { push @{$subfields}, $self->_create_subfield($code,%+); } } else { push @{$subfields}, $self->_create_subfield(undef,%+); } $i++; } if(0 == $i) { _throw("Invalid subfield spec detected.", $self->{_parsed}->{subfields}); } return $subfields; } sub _create_subfield { my ($self,$code,%args) = @_; # create a new Subfield my $subfield = MARC::Spec::Subfield->new($code // $args{code}); if(defined $args{index}) { $subfield->set_index_start_end($args{index}); } if(defined $args{charpos}) { $subfield->set_char_start_end($args{charpos}); } # handle subspecs if(defined $args{subspecs}) { my $subfield_subspecs = $self->_match_subspecs($args{subspecs}); $self->_populate_subspecs($subfield, $subfield_subspecs, [$self->{field_base}, $subfield->base]); } return $subfield; } sub _match_subspecs { my ($self, $subspecs) = @_; my @subspecs; foreach ($subspecs =~ /$SUBSPEC/g) { push @subspecs, [split(/(?new; foreach my $side (('left', 'right')) { if(defined $+{$side}) { if('\\' ne substr $+{$side},0,1) { my $spec = _spec_context($+{$side},$context); # this prevents the spec parsed again if($cache{$spec}) { $subSpec->$side( $cache{$spec} ); } else { $subSpec->$side( MARC::Spec::Parser->new($spec)->marcspec ); $cache{$spec} = $subSpec->$side; } } else { $subSpec->$side( MARC::Spec::Comparisonstring->new(substr $+{$side},1) ); } } elsif($side eq 'left') { my $spec = _spec_context(@{$context}[$#{$context}],$context); if($cache{$spec}) { $subSpec->left( $cache{$spec} ); } else { $subSpec->left( MARC::Spec::Parser->new($spec)->marcspec ); $cache{$spec} = $subSpec->left; } } else { _throw("Right hand subTerm is missing.", $subTerms); } } if(defined $+{operator}) { $subSpec->operator( $+{operator} )} return $subSpec; } sub _spec_context { my ($spec, $context) = @_; my $fieldContext = @{$context}[0]; my $fullcontext = join '', @{$context}; if($spec eq $fullcontext) { return $spec } my $firstChar = substr $spec,0,1; if($firstChar eq '^') { my $refPos = index $fullcontext, $firstChar; if(0 <= $refPos) { return substr($fullcontext,0,$refPos)."$spec"; } return "$fieldContext"."$spec"; } if($firstChar eq '$') { return $fieldContext.$spec } if($firstChar =~ /\[|\//) { my $refPos = rindex $fullcontext, $firstChar; if(0 <= $refPos) { if('$' ne substr $fullcontext,$refPos - 1,1) { return substr($fullcontext,0,$refPos)."$spec"; } } return "$fullcontext"."$spec"; } return $spec; } sub _do_checks { my ($spec, $min_length) = @_; if(ref \$spec ne 'SCALAR') { _throw("Argument must be of type SCALAR.", ref \$spec); } if($spec =~ /\s/s) { _throw("Whitespaces are not allowed.", $spec); } if($min_length > length $spec) { _throw("Spec must be at least ".$min_length." chracters long.", $spec); } return; } sub _throw { my ($message, $hint) = @_; croak 'MARCspec Parser exception. '.$message.' Tried to parse: '.$hint; } 1; __END__ =encoding utf-8 =head1 NAME MARC::Spec::Parser - parses a MARCspec as string =head1 SYNOPSIS use MARC::Spec::Parser; my $parser = MARC::Spec::Parser->new('245$a'); my $ms = $parser->marcspec; say ref $ms; # MARC::Spec =head1 DESCRIPTION MARC::Spec::Parser parses a MARCspec as string into a L. L is a L parser and validator. =head1 METHODS =head2 new(Str) Create a new MARC::Spec::Parser instance. Parameter must be a MARCspec as string. =head1 ATTRIBUTES =head2 spec Obligatory. The parameter string the MARC::Spec::Parser was instantiated with. =head2 marcspec Instance of L. =head1 AUTHOR Carsten Klee C<< >> =head1 CONTRIBUTORS =over =item * Johann Rolschewski, C<< >> =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2016 by Carsten Klee. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 BUGS Please report any bugs to L =head1 SEE ALSO =over =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =cut MARC-Spec-2.0.3/lib/MARC/Spec/Field.pm0000755001161400116140000001107413215154435016026 0ustar devel2devel2package MARC::Spec::Field; use Moo; use namespace::clean; extends 'MARC::Spec::Structure'; our $VERSION = '2.0.3'; has tag => ( is => 'rw', required => 1 ); sub BUILDARGS { my ($class, @args) = @_; if (@args % 2 == 1) { unshift @args, "tag" } return { @args }; } 1; __END__ =encoding utf-8 =head1 NAME MARC::Spec::Field - field specification =head1 SYNOPSIS use MARC::Spec::Field; my $field = MARC::Spec::Field->new('246'); say ref $field; # MARC::Spec::Field say $field->tag; # 246 say $field->index_start; # 0 say $field->index_end; # '#' =head1 DESCRIPTION MARC::Spec::Field is the field specification of a L. See L for further details on the syntax. =head1 METHODS Some methods are inherited from L. =head2 new(Str) Create a new MARC::Spec::Field instance. Parameter must be a valid MARCspec field tag. =head2 add_subspec(MARC::Spec::Subspec) Appends a subspec to the array of the attribute subspecs. Parameter must be an instance of L. =head2 add_subspecs(ArrayRef[MARC::Spec::Subspec]) Appends subspecs to the array of the attribute subspecs. Parameter must be an ArrayRef and elements must be instances of L. =head2 to_string Returns the spec as a string. =head1 PREDICATES Some predicates are inherited from L. =head2 has_char_start True if attribute char_start has an value and false otherwise. =head2 has_char_end True if attribute char_end has an value and false otherwise. =head2 has_char_pos True if attribute char_pos has an value and false otherwise. =head2 has_subspecs Returns true if attribute subspecs has an value and false otherwise. =head1 ATTRIBUTES Some attributes are inherited from L. =head2 base Obligatory. Scalar. The base Field spec without subspecs. =head2 tag Obligatory. The field tag. =head2 char_pos If defined, the character position or range. Only present if MARC::Spec::Field::$char_start is defined. =head2 char_start If defined, the beginning character position of a character position or range. =head2 char_end If defined, the ending character position of a character position or range. Only present if MARC::Spec::Field::$char_start is defined. =head2 char_length The difference of MARC::Spec::Field::$char_start and MARC::Spec::Field::$char_end if both are numeric (or else -1). Only present if MARC::Spec::Field::$char_start is defined. =head2 char_pos If defined, the character position or range. Only present if MARC::Spec::Field::$char_start is defined. =head2 index_start Obligatory. The beginning index of field repetitions. Maybe a positiv integer or the character '#'. Default is 0. =head2 index_end Obligatory. The ending index of field repetitions. Maybe a positiv integer or the character '#'. Default is '#'. =head2 index_length Obligatory. The difference of MARC::Spec::Field::$index_start and MARC::Spec::Field::$index_end if both are numeric. Default is -1. =head2 subspecs Optional. An array of instances of L, thus all subspecs in this array MUST be validated as a combination with the boolean 'AND', and/or an array of arrays (AoA) of instances of L, thus all subspecs in this AoA must be validated as a combination with the boolean 'OR'. See L for description of attributes of L. =head1 AUTHOR Carsten Klee C<< >> =head1 CONTRIBUTORS =over =item * Johann Rolschewski, C<< >> =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2016 by Carsten Klee. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 BUGS Please report any bugs to L =head1 SEE ALSO =over =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =cut MARC-Spec-2.0.3/lib/MARC/Spec/Subfield.pm0000755001161400116140000001111413215154435016533 0ustar devel2devel2package MARC::Spec::Subfield; use Moo; use namespace::clean; our $VERSION = '2.0.3'; extends 'MARC::Spec::Structure'; has code => ( is => 'rw', required => 1 ); sub BUILDARGS { my ($class, @args) = @_; if (@args % 2 == 1) { unshift @args, "code" } return { @args }; } 1; __END__ =encoding utf-8 =head1 NAME MARC::Spec::Subfield - subfield specification =head1 SYNOPSIS use MARC::Spec; my $ms = MARC::Spec->new('245$a/0-2); say ref $ms->subfields; # ARRAY say ref $ms->subfields->[0]; # MARC::Spec::Subfield =head1 DESCRIPTION MARC::Spec::Subfield is the subfield specification of a L. See L for further details on the syntax. =head1 METHODS Some methods are inherited from L. =head2 new Create a new MARC::Spec::Subfield instance. =head2 add_subspec(MARC::Spec::Subspec) Appends a subspec to the array of the attribute subspecs. Parameter must be an instance of L. Inherited from L. =head2 add_subspecs(ArrayRef[MARC::Spec::Subspec]) Appends subspecs to the array of the attribute subspecs. Parameter must be an ArrayRef and elements must be instances of L. Inherited from L. =head2 to_string Returns the spec as a string. Inherited from L. =head1 PREDICATES Some predicates are inherited from L. =head2 has_char_start True if attribute char_start has an value and false otherwise. =head2 has_char_end True if attribute char_end has an value and false otherwise. =head2 has_char_pos True if attribute char_pos has an value and false otherwise. =head2 has_subspecs Returns true if attribute subspecs has an value and false otherwise. =head1 ATTRIBUTES Some attributes are inherited from L. =head2 base Obligatory. The base Subfield spec without subspecs. =head2 code Obligatory. The subfield code. =head2 char_pos If defined, the character position or range. Only present if MARC::Spec::Subfield::$char_start is defined. =head2 char_start If defined, the beginning character position of a character position or range. =head2 char_end If defined, the ending character position of a character position or range. Only present if MARC::Spec::Subfield::$char_start is defined. =head2 char_length The difference of MARC::Spec::Subfield::$char_start and MARC::Spec::Field::$char_end if both are numeric (or else -1). Only present if MARC::Spec::Subfield::$char_start is defined. =head2 index_start Obligatory. The beginning index of subfield repetitions. Maybe a positiv integer or the character '#'. Default is 0. =head2 index_end Obligatory. The ending index of subfield repetitions. Maybe a positiv integer or the character '#'. Default is '#'. =head2 index_length Obligatory. The difference of MARC::Spec::Subfield::$index_start and MARC::Spec::Subfield::$index_end if both are numeric. Default is -1. =head2 subspecs Optional an array of instances of L, thus all subspecs in this array MUST be validated as a combination with the boolean 'AND', and/or an array of arrays (AoA) of instances of L, thus all subspecs in this AoA must be validated as a combination with the boolean 'OR'. See L for description of attributes of L. =head1 AUTHOR Carsten Klee C<< >> =head1 CONTRIBUTORS =over =item * Johann Rolschewski, C<< >> =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2016 by Carsten Klee. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 BUGS Please report any bugs to L =head1 SEE ALSO =over =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =cut MARC-Spec-2.0.3/lib/MARC/Spec/Indicator.pm0000644001161400116140000001233613215154435016716 0ustar devel2devel2package MARC::Spec::Indicator; use Moo; use Carp qw(croak); use namespace::clean; our $VERSION = '2.0.3'; has position => ( is => 'rw', isa => sub { croak('For indicator position, only digit "1" or "2" is allowed.') if($_[0] !~ /1|2/) }, required => 1 ); has base => ( is => 'rwp', lazy => 1, builder => '_base' ); has subspecs => ( is => 'rwp', isa => sub { foreach my $and (@{$_[0]}) { if(ref $and eq 'ARRAY') { foreach my $or (@{$and}) { croak('Subspec is not an instance of MARC::Spec::Subspec.') if(ref $or ne 'MARC::Spec::Subspec') } } else { croak('Subspec is not an instance of MARC::Spec::Subspec.') if(ref $and ne 'MARC::Spec::Subspec') } } }, predicate => 1 ); sub BUILDARGS { my ($class, @args) = @_; if (@args % 2 == 1) { unshift @args, "position" } return { @args }; } sub _base { my ($self) = @_; return '^'.$self->position; } sub add_subspec { my ($self, $subspec) = @_; if(!$self->has_subspecs) { $self->_set_subspecs([$subspec]); } else { my @subspecs = ( @{$self->subspecs}, $subspec ); $self->_set_subspecs( \@subspecs ) } } sub add_subspecs { my ($self, $subspecs) = @_; if (ref $subspecs ne 'ARRAY') { croak('Subspecs is not an ARRAYRef!') } if(!$self->has_subspecs) { $self->_set_subspecs($subspecs) } else { my @merged = @{$self->subspecs}; push @merged, @{$subspecs}; $self->_set_subspecs( \@merged ) } } sub to_string { my ($self) = @_; my $string = $self->base; if($self->has_subspecs) { my @outer = (); foreach my $ss (@{$self->subspecs}) { if(ref $ss eq 'ARRAY') { my $inner = join '|', map {$_->to_string()} @{$ss}; push @outer, $inner; } else { push @outer, $ss->to_string(); } } my $joined = join '}{', @outer; $string .= '{'. $joined .'}'; } return $string; } 1; __END__ =encoding utf-8 =head1 NAME MARC::Spec::Indicator - indicator specification =head1 SYNOPSIS use MARC::Spec::Indicator; my $indicator = MARC::Spec::Indicator->new('2'); say ref $indicator; # MARC::Spec::Indicator say $field->position; # 2 =head1 DESCRIPTION MARC::Spec::Indicator is the indicator specification of a L. See L for further details on the syntax. =head1 METHODS =head2 new(Str) Create a new MARC::Spec::Indicator instance. Parameter must be a valid MARCspec indicatorPosition. =head2 add_subspec(MARC::Spec::Subspec) Appends a subspec to the array of the attribute subspecs. Parameter must be an instance of L. =head2 add_subspecs(ArrayRef[MARC::Spec::Subspec]) Appends subspecs to the array of the attribute subspecs. Parameter must be an ArrayRef and elements must be instances of L. =head2 to_string Returns the spec as a string. =head1 PREDICATES =head2 has_position True if attribute position has an value and false otherwise. =head2 has_subspecs Returns true if attribute subspecs has an value and false otherwise. =head1 ATTRIBUTES Some attributes are inherited from L. =head2 base Obligatory. Scalar. The base Field spec without subspecs. =head2 position Obligatory. The indicator position. =head2 subspecs Optional. An array of instances of L, thus all subspecs in this array MUST be validated as a combination with the boolean 'AND', and/or an array of arrays (AoA) of instances of L, thus all subspecs in this AoA must be validated as a combination with the boolean 'OR'. See L for description of attributes of L. =head1 AUTHOR Carsten Klee C<< >> =head1 CONTRIBUTORS =over =item * Johann Rolschewski, C<< >> =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2016 by Carsten Klee. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 BUGS Please report any bugs to L =head1 SEE ALSO =over =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =cut