| 1 | package MARC::Spec; | ||||||||||
| 2 | |||||||||||
| 3 | 13 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 13 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 13 | ▶ | use MARC::Spec::Parser; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 13 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 13 | our $VERSION = '1.0.0'; | |||||||||
| 9 | |||||||||||
| 10 | has field => ( | ||||||||||
| 11 | is => 'rw', | ||||||||||
| 12 | isa => sub { | ||||||||||
| 13 | 40 | ▶ | croak('Field is not an instance of MARC::Spec::Field') | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||
| 14 | if(ref $_[0] ne 'MARC::Spec::Field') | ||||||||||
| 15 | }, | ||||||||||
| 16 | 13 | required => 1 | |||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | has subfields => ( | ||||||||||
| 20 | is => 'rwp', | ||||||||||
| 21 | isa => sub { | ||||||||||
| 22 | croak('Subfield is not an instance of MARC::Spec::Subfield.') | ||||||||||
| 23 | 25 | ▶ | if(grep {ref $_ ne 'MARC::Spec::Subfield'} @{$_[0]}) | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||
| 24 | }, | ||||||||||
| 25 | 13 | predicate => 1 | |||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | sub BUILDARGS { | ||||||||||
| 29 | 40 | ▶ | my ($class, @args) = @_; | ||||||||
|
Subroutine
BUILDARGS: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 30 | 40 | ▶ | if (@args % 2 == 1) { unshift @args, "field" } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 40 | return { @args }; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | sub add_subfield { | ||||||||||
| 35 | 2 | ▶ | my ($self, $subfield) = @_; | ||||||||
|
Subroutine
add_subfield: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||
| 36 | 2 | ▶ | if(!$self->has_subfields) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 2 | $self->_set_subfields([$subfield]); | |||||||||
| 38 | } else { | ||||||||||
| 39 | 0 | my @subfields = ( @{$self->subfields}, $subfield ); | |||||||||
| 40 | 0 | $self->_set_subfields( \@subfields ); | |||||||||
| 41 | } | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | sub add_subfields { | ||||||||||
| 45 | 23 | ▶ | my ($self, $subfields) = @_; | ||||||||
|
Subroutine
add_subfields: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||
| 46 | 23 | ▶ | if (ref $subfields ne 'ARRAY') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | croak('Subfields is not an ARRAYRef!') | |||||||||
| 48 | } | ||||||||||
| 49 | 23 | ▶ | if(!$self->has_subfields) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 22 | $self->_set_subfields($subfields); | |||||||||
| 51 | } else { | ||||||||||
| 52 | 1 | my @merged = ( @{$self->subfields}, @{$subfields} ); | |||||||||
| 53 | 1 | $self->_set_subfields( \@merged ) | |||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | sub parse { | ||||||||||
| 58 | 30 | ▶ | my ($spec) = @_; | ||||||||
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 59 | 30 | my $parser = MARC::Spec::Parser->new($spec); | |||||||||
| 60 | 19 | return $parser->marcspec; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | sub to_string { | ||||||||||
| 64 | 9 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
to_string: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 65 | 9 | my $string = $self->field->to_string(); | |||||||||
| 66 | 9 | ▶ | if($self->has_subfields) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 5 | foreach my $sf (@{$self->subfields}) { | |||||||||
| 68 | 5 | $string .= $sf->to_string() | |||||||||
| 69 | } | ||||||||||
| 70 | } | ||||||||||
| 71 | 9 | return $string; | |||||||||
| 72 | } | ||||||||||
| 73 | 13 | 1; | |||||||||
| 74 | __END__ | ||||||||||