line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Exporter::Breaker; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
395508
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
8
|
|
4
|
1
|
|
|
1
|
|
260
|
use Catmandu::Util qw(:is); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
284
|
|
5
|
1
|
|
|
1
|
|
9
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
527
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
105
|
|
7
|
1
|
|
|
1
|
|
7
|
use Path::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
8
|
1
|
|
|
1
|
|
7
|
use namespace::clean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.141'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Exporter'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has fields => (is => 'ro'); |
15
|
|
|
|
|
|
|
has handler => (is => 'rw', default => sub {'json'} , coerce => \&_coerce_handler ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _coerce_handler { |
18
|
4
|
|
|
4
|
|
6144
|
my ($handler) = @_; |
19
|
|
|
|
|
|
|
|
20
|
4
|
50
|
33
|
|
|
48
|
return $handler if is_invocant($handler) or is_code_ref($handler); |
21
|
|
|
|
|
|
|
|
22
|
4
|
50
|
33
|
|
|
41
|
if (is_string($handler) && !is_number($handler)) { |
23
|
4
|
50
|
|
|
|
26
|
my $class = $handler =~ /^\+(.+)/ ? $1 |
24
|
|
|
|
|
|
|
: "Catmandu::Exporter::Breaker::Parser::$handler"; |
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
|
|
8
|
my $handler; |
27
|
4
|
|
|
|
|
37
|
eval { |
28
|
4
|
|
|
|
|
17
|
$handler = Catmandu::Util::require_package($class)->new; |
29
|
|
|
|
|
|
|
}; |
30
|
4
|
50
|
|
|
|
20
|
if ($@) { |
31
|
0
|
|
|
|
|
0
|
croak $@; |
32
|
|
|
|
|
|
|
} else { |
33
|
4
|
|
|
|
|
77
|
return $handler; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
0
|
|
|
|
|
|
die "Need a Breaker::Parser" |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub add { |
42
|
|
|
|
|
|
|
my ($self, $data) = @_; |
43
|
|
|
|
|
|
|
$self->handler->add($data,$self->fh,$self); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub commit { |
47
|
|
|
|
|
|
|
my ($self) = @_; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
if ($self->fields) { |
50
|
|
|
|
|
|
|
my $tags = $self->handler->tags // {}; |
51
|
|
|
|
|
|
|
my @tags = map { "$_\n" } sort keys %$tags; |
52
|
|
|
|
|
|
|
path($self->fields)->spew_utf8(@tags); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=pod |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 NAME |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Catmandu::Exporter::Breaker - Package that exports OAI-PMH DC in a Breaker format |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 SYNOPSIS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Using the default breaker |
70
|
|
|
|
|
|
|
$ catmandu convert JSON to Breaker < data.json |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Using a OAI_DC breaker |
73
|
|
|
|
|
|
|
$ catmandu convert OAI --url http://biblio.ugent.be/oai to Breaker |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Using a MARCXML breaker |
76
|
|
|
|
|
|
|
$ catmandu convert MARC to Breaker --handler marc |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Using an XML breaker |
79
|
|
|
|
|
|
|
$ catmandu convert XML --path book to Breaker --handler xml < t/book.xml > data.breaker |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Write a fields file containing all unique fields |
82
|
|
|
|
|
|
|
$ catmandu convert XML --path book to Breaker --handler xml --fields data.fields < t/book.xml > data.breaker |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Find the usage statistics of fields in the XML file above |
85
|
|
|
|
|
|
|
$ catmandu breaker data.breaker |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Convert the Breaker format by line into JSON |
88
|
|
|
|
|
|
|
$ catmandu convert Breaker < data.breaker |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Convert the Breaker format by line into JSON using the fields file |
91
|
|
|
|
|
|
|
$ catmandu convert Breaker --fields data.fields < data.breaker |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DESCRIPTION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Inspired by the article "Metadata Analysis at the Command-Line" by Mark Phillips in |
96
|
|
|
|
|
|
|
L<http://journal.code4lib.org/articles/7818> this exporter breaks a metadata records |
97
|
|
|
|
|
|
|
into the Breaker format which can be analyzed further by command line tools. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 BREAKER FORMAT |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
<record-identifier><tab><metadata-field><tab><metadata-value> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SEE ALSO |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L<Catmandu::Importer::Breaker> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |