Prog/InvIndex/Meta.pm

filter: Statementstmt 88.8% 16 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.6% 22 / 24 CC 1 SCAR 0.5
CC
1
Cov
89%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Prog/Test/Indexer.pm ↑ Summary Prog/Native/Indexer.pm »
1 package SWISH::Prog::InvIndex::Meta;
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use base qw( SWISH::Prog::Class );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 0 ▶use SWISH::3 qw( :constants );
Subroutine BEGIN: called CC=1 SCAR=2.6
8  
9 our $VERSION = '0.75';
10  
11 __PACKAGE__->mk_accessors(qw( invindex ));
12 __PACKAGE__->mk_ro_accessors(qw( file data ));
13  
14 # index metadata. read/write libswish3 file xml format.
15 #
16  
17 sub swish_header_file {
18 return 'swish.xml';
19 }
20  
21 sub init {
22 my $self = shift;
23 $self->SUPER::init(@_);
24 $self->{file} ||= $self->invindex->path->file( $self->swish_header_file );
25 if ( !-s $self->{file} ) {
26 confess("No such file: $self->{file}");
27 }
28 $self->{data} = XMLin("$self->{file}");
29  
30 #warn Data::Dump::dump( $self->{data} );
31  
32 my $props = $self->{data}->{PropertyNames};
33  
34 # start with the built-in PropertyNames,
35 # which cannot be aliases for anything.
36 my %propnames = map { $_ => { alias_for => undef } }
37 keys %{ SWISH_DOC_PROP_MAP() };
38 $propnames{swishrank} = { alias_for => undef };
39 $propnames{score} = { alias_for => undef };
40 my @pure_props;
41 my %prop_map;
42 for my $name ( keys %$props ) {
43 $propnames{$name} = { alias_for => undef };
44 if ( exists $props->{$name}->{alias_for} ) {
45 $propnames{$name}->{alias_for} = $props->{$name}->{alias_for};
46 $prop_map{$name} = $props->{$name}->{alias_for};
47 }
48 else {
49 push @pure_props, $name;
50 }
51 }
52 $self->{_propnames} = \%propnames;
53 $self->{_pure_props} = \@pure_props;
54 $self->{_prop_map} = \%prop_map;
55 }
56  
57 sub get_properties {
58 return shift->{_propnames};
59 }
60  
61 sub get_property_map {
62 return shift->{_prop_map};
63 }
64  
65 sub get_pure_properties {
66 return shift->{_pure_props};
67 }
68  
69 sub AUTOLOAD {
70 my $self = shift;
71 my $method = our $AUTOLOAD;
72 $method =~ s/.*://;
73 return if $method eq 'DESTROY';
74  
75 if ( exists $self->{data}->{$method} ) {
76 return $self->{data}->{$method};
77 }
78 croak "no such Meta key: $method";
79 }
80  
81 1;
82  
83 __END__
« Prog/Test/Indexer.pm ↑ Summary Prog/Native/Indexer.pm »