Why not adopt me?
NAME
Lingua::Abbreviate::Hierarchy - Shorten verbose namespaces
VERSION
This document describes Lingua::Abbreviate::Hierarchy version 0.01
SYNOPSIS
use Lingua::Abbreviate::Hierarchy;
my $abr = Lingua::Abbreviate::Hierarchy->new( keep => 1 );
$abr->add_namespace(qw(
comp.lang.perl.misc
comp.lang.perl.advocacy
));
# gets 'c.l.p.misc'
my $clpm = $abr->ab('comp.lang.perl.misc');
# abbreviate an array
my @ab = $abr->ab(qw(
comp.lang.perl.misc
comp.lang.perl.advocacy
));
DESCRIPTION
It's a common practice to abbreviate the elements of namespaces like this:
comp.lang.perl.misc -> c.l.p.misc
comp.lang.perl.advocacy -> c.l.p.advocacy
This module performs such abbreviation. It guarantees that generated abbreviations are long enough to be unique within the current namespace.
INTERFACE
To abbreviate names within a namespace use the module:
use Lingua::Ab::H; # use abbreviated name
Create a new abbreviator:
my $abr = Lingua::Ab::H->new( keep => 1 );
Set up the namespace:
$abr->add_namespace(qw(
comp.lang.perl.misc
comp.lang.perl.advocacy
));
Get your abbreviations:
# gets 'c.l.p.misc'
my $clpm = $abr->ab('comp.lang.perl.misc');
# abbreviate an array
my @ab = $abr->ab(qw(
comp.lang.perl.misc
comp.lang.perl.advocacy
));
Often the namespace will be larger; for example if you wanted to generate abbreviations that would be unique within the entire comp.lang.* hierarchy you would add all the terms in that space to the abbreviator.
new
Create a new abbreviator. Options may be passed as key, value pairs:
my $abr = Lingua::Ab::H->new(
keep => 1,
sep => '::'
);
The following options are recognised:
sep
-
The string that separates components in the namespace. For example '.' for domain names or '::' for Perl package names;
only
-
Abbreviate only the initial N elements in the name.
keep
-
Leave N elements at the end of the name unabbreviated.
max
-
Abbreviate from the left until the generated abbreviation contains N or fewer characters. If
only
is specified then at least that many elements will be abbreviated. Ifkeep
is specified that many trailing elements will be unabbreviated.May return more than N characters if the fully abbreviated name is still too long.
trunc
-
A truncation string (which may be empty). When
trunc
is supplied the generated abbreviation will always be <=max
characters and will be prefixed by the truncation string. flip
-
Normally we consider the namespace to be rooted at the left (like a filename or package name). Set
flip
to true to process right-rooted namespaces (like domain names). ns
-
Supply a reference to an array containing namespace terms. See
add_namespace
for more details.
add_namespace
Add terms to the abbreviator's namespace:
$abr->add_namespace( 'foo.com', 'bar.com' );
When abbreviating a term only those elements of the term that fall within the namespace will be abbreviated. Elements outside the namespace will be untouched.
ab
Abbreviate one or more terms:
my $short = $abr->ab( 'this.is.a.long.name' );
Or with an array:
my @short = $abr->ab( @long );
DEPENDENCIES
None.
INCOMPATIBILITIES
None reported.
BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests to bug-lingua-abbreviate-hierarchy@rt.cpan.org
, or through the web interface at http://rt.cpan.org.
AUTHOR
Andy Armstrong <andy@hexten.net>
LICENCE AND COPYRIGHT
Copyright (c) 2009, Andy Armstrong <andy@hexten.net>
.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.