line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dezi::InvIndex::Header; |
2
|
10
|
|
|
10
|
|
56
|
use Moose; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
78
|
|
3
|
|
|
|
|
|
|
with 'Dezi::Role'; |
4
|
10
|
|
|
10
|
|
68976
|
use Types::Standard qw( InstanceOf HashRef ); |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
372
|
|
5
|
10
|
|
|
10
|
|
7140
|
use Dezi::Types qw( DeziInvIndex ); |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
82
|
|
6
|
10
|
|
|
10
|
|
12273
|
use MooseX::Types::Path::Class; |
|
10
|
|
|
|
|
3515205
|
|
|
10
|
|
|
|
|
121
|
|
7
|
10
|
|
|
10
|
|
9917
|
use Carp; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
849
|
|
8
|
10
|
|
|
10
|
|
5301
|
use SWISH::3 qw( :constants ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use namespace::autoclean; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.014'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'invindex' => ( is => 'rw', isa => DeziInvIndex, required => 1 ); |
15
|
|
|
|
|
|
|
has 'file' => ( is => 'ro', isa => 'Path::Class::File', coerce => 1, ); |
16
|
|
|
|
|
|
|
has 'data' => ( is => 'ro', isa => HashRef ); |
17
|
|
|
|
|
|
|
has 'swish3_config' => ( is => 'ro', isa => InstanceOf ['SWISH::3::Config'] ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# index metadata. read/write libswish3 file xml format. |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub header_file { |
23
|
|
|
|
|
|
|
return SWISH_HEADER_FILE(); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# back compat |
27
|
|
|
|
|
|
|
sub swish_header_file { shift->header_file } |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub BUILD { |
30
|
|
|
|
|
|
|
my $self = shift; |
31
|
|
|
|
|
|
|
$self->{file} = $self->invindex->path->file( $self->header_file ); |
32
|
|
|
|
|
|
|
if ( !-s $self->{file} ) { |
33
|
|
|
|
|
|
|
confess("No such file: $self->{file}"); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
$self->{swish3_config} = SWISH::3::Config->read("$self->{file}"); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# unroll swish3_config into a local perl hash |
38
|
|
|
|
|
|
|
$self->_build_data(); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#warn Data::Dump::dump( $self->{data} ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$self->_build_property_maps(); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#SWISH::3->dump( $self ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _build_data { |
48
|
|
|
|
|
|
|
my $self = shift; |
49
|
|
|
|
|
|
|
my $s3config = $self->swish3_config; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$self->{data} = { |
52
|
|
|
|
|
|
|
SWISH_PROP() => $s3config->get_properties->_as_hash, |
53
|
|
|
|
|
|
|
SWISH_META() => $s3config->get_metanames->_as_hash, |
54
|
|
|
|
|
|
|
SWISH_MIME() => $s3config->get_mimes->_as_hash, |
55
|
|
|
|
|
|
|
SWISH_PARSERS() => $s3config->get_parsers->_as_hash, |
56
|
|
|
|
|
|
|
SWISH_INDEX() => $s3config->get_index->_as_hash, |
57
|
|
|
|
|
|
|
SWISH_ALIAS() => $s3config->get_aliases->_as_hash, |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# add any leftovers |
61
|
|
|
|
|
|
|
my $misc = $s3config->get_misc(); |
62
|
|
|
|
|
|
|
for my $key ( @{ $misc->keys } ) { |
63
|
|
|
|
|
|
|
next if exists $self->{data}->{$key}; |
64
|
|
|
|
|
|
|
$self->{data}->{$key} = $misc->get($key); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#SWISH::3->dump($self); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _build_property_maps { |
72
|
|
|
|
|
|
|
my $self = shift; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $props = $self->swish3_config->get_properties; |
75
|
|
|
|
|
|
|
my $prop_names = $props->keys; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# start with the built-in PropertyNames, |
78
|
|
|
|
|
|
|
# which cannot be aliases for anything. |
79
|
|
|
|
|
|
|
my %propnames = map { $_ => { alias_for => undef } } |
80
|
|
|
|
|
|
|
keys %{ SWISH_DOC_PROP_MAP() }; |
81
|
|
|
|
|
|
|
$propnames{swishrank} = { alias_for => undef }; |
82
|
|
|
|
|
|
|
$propnames{score} = { alias_for => undef }; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my @pure_props; |
85
|
|
|
|
|
|
|
my %prop_map; |
86
|
|
|
|
|
|
|
for my $name (@$prop_names) { |
87
|
|
|
|
|
|
|
my $property = $props->get($name); |
88
|
|
|
|
|
|
|
$propnames{$name} = { alias_for => undef }; |
89
|
|
|
|
|
|
|
if ( defined $property->alias_for ) { |
90
|
|
|
|
|
|
|
$propnames{$name}->{alias_for} = $property->alias_for; |
91
|
|
|
|
|
|
|
$prop_map{$name} = $property->alias_for; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else { |
94
|
|
|
|
|
|
|
push @pure_props, $name; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
$self->{_propnames} = \%propnames; |
98
|
|
|
|
|
|
|
$self->{_pure_props} = \@pure_props; |
99
|
|
|
|
|
|
|
$self->{_prop_map} = \%prop_map; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub get_properties { |
103
|
|
|
|
|
|
|
return shift->{_propnames}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub get_property_map { |
107
|
|
|
|
|
|
|
return shift->{_prop_map}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub get_pure_properties { |
111
|
|
|
|
|
|
|
return shift->{_pure_props}; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub AUTOLOAD { |
115
|
|
|
|
|
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
my $method = our $AUTOLOAD; |
117
|
|
|
|
|
|
|
$method =~ s/.*://; |
118
|
|
|
|
|
|
|
return if $method eq 'DESTROY'; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
if ( exists $self->{data}->{$method} ) { |
121
|
|
|
|
|
|
|
return $self->{data}->{$method}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
confess "no such Header key: $method"; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=pod |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 NAME |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Dezi::InvIndex::Header - read/write InvIndex metadata |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SYNOPSIS |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
use Data::Dump qw( dump ); |
141
|
|
|
|
|
|
|
use Dezi::InvIndex; |
142
|
|
|
|
|
|
|
my $index = Dezi::InvIndex->new(path => 'path/to/index'); |
143
|
|
|
|
|
|
|
my $meta = $index->meta; # isa Dezi::InvIndex::Header object |
144
|
|
|
|
|
|
|
for my $key (keys %{ $meta->data }) { |
145
|
|
|
|
|
|
|
dump $meta->$key; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 DESCRIPTION |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
A Dezi::InvIndex::Header object represents the metadata for an |
151
|
|
|
|
|
|
|
InvIndex. It supports the Swish3 C<swish.xml> header file format only |
152
|
|
|
|
|
|
|
at this time. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 CONSTANTS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
All the L<SWISH::3> constants are imported into this namespace, |
157
|
|
|
|
|
|
|
including: |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 SWISH_DOC_PROP_MAP |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 METHODS |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 header_file |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Class or object method. Returns the basename of the header file. |
166
|
|
|
|
|
|
|
Default is C<swish.xml>. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 swish_header_file |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Alias for header_file(). For backwards compatability with SWISH::Prog. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 BUILD |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Read and initialize the header_file(). |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 data |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
The contents of the header file as a Perl hashref. This is a read-only |
179
|
|
|
|
|
|
|
accessor. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 file |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
The full path to the header_file() file. This is a read-only accessor. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 invindex |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
The Dezi::InvIndex object which the Dezi::InvIndex::Header |
188
|
|
|
|
|
|
|
object represents. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 get_properties |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Returns hashref of PropertyNames with aliases resolved. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 get_pure_properties |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Returns arrayref of PropertyName values, excluding aliases. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 get_property_map |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Returns hashref of alias names to pure names. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 AUTHOR |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Peter Karman, E<lt>karpet@dezi.orgE<gt> |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 BUGS |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-dezi-app at rt.cpan.org>, or through |
211
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dezi-App>. |
212
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 SUPPORT |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
perldoc Dezi::InvIndex::Header |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
You can also look for information at: |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=over 4 |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=item * Website |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
L<http://dezi.org/> |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=item * IRC |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
#dezisearch at freenode |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item * Mailing list |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
L<https://groups.google.com/forum/#!forum/dezi-search> |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dezi-App> |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Dezi-App> |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=item * CPAN Ratings |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Dezi-App> |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item * Search CPAN |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
L<https://metacpan.org/dist/Dezi-App/> |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=back |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Copyright 2014 by Peter Karman |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
259
|
|
|
|
|
|
|
it under the terms of the GPL v2 or later. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 SEE ALSO |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
L<http://dezi.org/>, L<http://swish-e.org/>, L<http://lucy.apache.org/> |