NAME

Dezi::Utils - utility variables and methods

SYNOPSIS

use Dezi::Utils;

my $ext = Dezi::Utils->get_file_ext( $filename );
my $mime = Dezi::Utils->get_mime( $filename );
if (Dezi::Utils->looks_like_gz( $filename )) {
    $mime = Dezi::Utils->get_real_mime( $filename );
}
my $parser = Dezi::Utils->get_parser_for_mime( $mime );

DESCRIPTION

This class provides commonly used variables and methods shared by many classes in the Dezi project.

VARIABLES

$ExtRE

Regular expression of common file type extensions.

%ParserTypes

Hash of MIME types to their equivalent parser. This hash is used to cache lookups in get_parser_for_mime(). You really don't want to mess with this, but documented in case you're brave or foolish.

$DefaultExtension

Defaults to html.

$DefaultMIME

Defaults to text/html.

METHODS

get_mime( url [, swish3] )

Returns MIME type for url, using optional swish3 instance to look it up. If swish3 is missing, will use the SWISH::3 default mapping.

mime_type( url [, ext ] )

Backcompat for SWISH::Prog::Utils. Use get_mime() instead, which is what this does internally.

get_parser_for_mime( mime [, swish3_object] )

Returns the SWISH::3 parser type for mime. This can be configured via the %ParserTypes class variable.

parser_for( url )

Backcompat for SWISH::Prog::Utils. Use get_parser_for_mime() instead, which is what this does internally.

path_parts( url [, regex ] )

Returns array of path, file and extension using the File::Basename module. If regex is missing or false, uses $ExtRE.

merge_swish3_config( key => value [, swish3] )

The SWISH::3 class currently does not allow for modification of the internal C structs from Perl space. Instead, the SWISH::3::Config->merge method can be used to parse XML strings. Since hand-crafting XML is tedious, this method eases the pain.

key should be a SWISH::3::Config reserved word. Use the SWISH::3::Constants for safety.

value is passed through perl_to_xml(). If value is a hashref, it should be a simple key/value set with strings. You may use arrayref values, where items in the array are strings.

The optional swish3 object is modified, or the internal singleton SWISH::3 object will be modified if swish3 is missing.

Example:

use SWISH::3 qw( :constants );
$utils->merge_swish3_config( 
    SWISH_PARSERS() => { 
        'XML'  => [ 'application/x-bar', 'application/x-foo' ],
        'HTML' => [ 'application/x-blue', 'application/x-red' ] 
    } 
);
$utils->merge_swish3_config(
    'foo' => 'bar'
);
$utils->get_parser_for_mime( 'application/x-foo' );   # returns 'XML'

get_swish3

Returns the class singleton.

perl_to_xml( ref, root_element [, strip_plural ] )

Similar to the XML::Simple XMLout() feature, perl_to_xml() will take a Perl data structure ref and convert it to XML, using root_element as the top-level element.

As of version 0.38 this method is now part of Search::Tools and included here simply as a backcompat feature.

write_log( args )

Logging method. By default writes to stderr via warn().

args is a key/value pair hash, with keys uri and msg.

write_log_line([char, width])

Writes char x width to stderr, to provide some visual separation when viewing logs. char defaults to - and width to 80.

AUTHOR

Peter Karman, <karpet@dezi.org>

BUGS

Please report any bugs or feature requests to bug-dezi-app at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dezi-App. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Dezi::Utils

You can also look for information at:

COPYRIGHT AND LICENSE

Copyright 2014 by Peter Karman

This library is free software; you can redistribute it and/or modify it under the terms of the GPL v2 or later.

SEE ALSO

http://dezi.org/, http://swish-e.org/, http://lucy.apache.org/