NAME

Package::Abbreviate - shorten package names

SYNOPSIS

    use Package::Abbreviate;
    
    my $pkg = "Foo::Bar::TooLong::PackageName";
    
    # no need to abbreviate!
    my $p = Package::Abbreviate->new(30);
    printf '%30s', $p->abbr($pkg); # Foo::Bar::TooLong::PackageName
    
    # a bit shorter
    my $p = Package::Abbreviate->new(28);
    printf '%28s', $p->abbr($pkg); # F::Bar::TooLong::PackageName
    
    # even shorter
    my $p = Package::Abbreviate->new(24);
    printf '%24s', $p->abbr($pkg); # F::B::TL::PackageName
    
    # even! ...oops
    my $p = Package::Abbreviate->new(20);
    printf '%20s', $p->abbr($pkg); # spits a warning
    
    # we can do it more eagerly with an option
    my $p = Package::Abbreviate->new(20, {eager => 1});
    printf '%20s', $p->abbr($pkg); # FB::TL::PackageName
    
    # more eagerly
    my $p = Package::Abbreviate->new(16, {eager => 1});
    printf '%16s', $p->abbr($pkg); # F::B::TL::PN
    
    # even more!
    my $p = Package::Abbreviate->new(10, {eager => 1});
    printf '%10s', $p->abbr($pkg); # FBTLPN
    
    # oops, there's nothing left to cut...
    my $p = Package::Abbreviate->new(5, {eager => 1});
    printf '%5s', $p->abbr($pkg); # spits a warning

DESCRIPTION

When you make a big table that contains a lot of data with (long) package names, you might want to shorten some of them. However, just trimming them with sprintf or substr may not work for you.

Package::Abbreviate shortens package names, but also tries not to do too much.

METHODS

new

takes a max length of abbreviations, and an optional hash reference to configure.

eager

lets Package::Abbreviate to shorten the basename and/or omit colons between monikers.

croak

croaks if an error occurs.

abbr

takes one or more package names and returns shortened ones.

If you pass more than one package names, Package::Abbreviate also tests if duplicated names are not generated.

SEE ALSO

Lingua::Abbreviate::Hierarchy

AUTHOR

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2014 by Kenichi Ishigaki.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.