App-Dochazka-CLI

 view release on metacpan or  search on metacpan

lib/App/Dochazka/CLI/Util.pm  view on Meta::CPAN

Returns a copy of the string. If any characters were actually removed in the
truncate operation, '...' is appended -- unless the maximum length is zero, in
which case the empty string is returned.

=cut

sub truncate_to {
    my ( $str, $mlen ) = validate_pos( @_, 
        { type => SCALAR|UNDEF },
        { 
            callbacks => {
                'greater than or equal to zero' => sub { shift() >= 0 },
            },
            optional => 1,
            type => SCALAR, 
        },
    );
    $mlen = 32 unless defined( $mlen );
    my $len = length $str || 0;  # $str might be undef
    return $str unless $len > $mlen;
    my $str_copy = substr( $str, 0, $mlen );



( run in 0.285 second using v1.01-cache-2.11-cpan-8d75d55dd25 )