Dezi-App
view release on metacpan or search on metacpan
lib/Dezi/InvIndex/Header.pm view on Meta::CPAN
package Dezi::InvIndex::Header;
use Moose;
with 'Dezi::Role';
use Types::Standard qw( InstanceOf HashRef );
use Dezi::Types qw( DeziInvIndex );
use MooseX::Types::Path::Class;
use Carp;
use SWISH::3 qw( :constants );
use namespace::autoclean;
our $VERSION = '0.016';
has 'invindex' => ( is => 'rw', isa => DeziInvIndex, required => 1 );
has 'file' => ( is => 'ro', isa => 'Path::Class::File', coerce => 1, );
has 'data' => ( is => 'ro', isa => HashRef );
has 'swish3_config' => ( is => 'ro', isa => InstanceOf ['SWISH::3::Config'] );
# index metadata. read/write libswish3 file xml format.
#
sub header_file {
return SWISH_HEADER_FILE();
}
# back compat
sub swish_header_file { shift->header_file }
sub BUILD {
my $self = shift;
$self->{file} = $self->invindex->path->file( $self->header_file );
if ( !-s $self->{file} ) {
confess("No such file: $self->{file}");
}
$self->{swish3_config} = SWISH::3::Config->read("$self->{file}");
# unroll swish3_config into a local perl hash
$self->_build_data();
#warn Data::Dump::dump( $self->{data} );
$self->_build_property_maps();
#SWISH::3->dump( $self );
}
sub _build_data {
my $self = shift;
my $s3config = $self->swish3_config;
$self->{data} = {
SWISH_PROP() => $s3config->get_properties->_as_hash,
SWISH_META() => $s3config->get_metanames->_as_hash,
SWISH_MIME() => $s3config->get_mimes->_as_hash,
SWISH_PARSERS() => $s3config->get_parsers->_as_hash,
SWISH_INDEX() => $s3config->get_index->_as_hash,
SWISH_ALIAS() => $s3config->get_aliases->_as_hash,
};
# add any leftovers
my $misc = $s3config->get_misc();
for my $key ( @{ $misc->keys } ) {
next if exists $self->{data}->{$key};
$self->{data}->{$key} = $misc->get($key);
}
#SWISH::3->dump($self);
}
sub _build_property_maps {
my $self = shift;
my $props = $self->swish3_config->get_properties;
my $prop_names = $props->keys;
( run in 0.983 second using v1.01-cache-2.11-cpan-39bf76dae61 )