Text-Elide

 view release on metacpan or  search on metacpan

lib/Text/Elide.pm  view on Meta::CPAN

    # return truncated string if only one word / part of word (no whitespace) -
    # ( ... but possibly with leading whitespace)
    return $string if $string =~ /^\s*\S+$/;
    ### require: $string =~ /\S\s+\S/
    croak "elipsis string ($elipsis) is longer than length ($length)\n"
        if length( $elipsis ) > $length
    ;
    ### require: length( $elipsis ) <= $length
    if ( $broken_word )
    {
        # remove partial word if crude truncation split mid-word
        $string =~ s/\s+\S+$//;
        ### require: $string =~ /\S$/
    }
    # if there is only one word ...
    unless ( $string =~ /\S\s+\S/ )
    {
        # check if room for elipsis ...
        if ( length( $string ) + length( $elipsis ) <= $length )
        {
            return $string . $elipsis;



( run in 0.590 second using v1.01-cache-2.11-cpan-5511b514fd6 )