NAME OpusVL::Text::Util - Simple text utilities VERSION version 0.09 SYNOPSIS This provides a couple of simple methods for playing with text. use OpusVL::Text::Util qw/truncate_text wrap_text/; my $truncated = truncate_text('a long string really', 10); # 'a long...' my $wrapped = truncate_text('a long string really', 10); $wrapped = "a long\nstring really"; EXPORT truncate_text This truncates a string close to the limit provided. It tries to break it on a word break if possible. It then appends a '...' to the string. This isn't included in the calculation of the length, so you may end up with 3 more characters than you specified. my $truncated = truncate_text('a long string really', 10); # 'a long...' wrap_text This method has a go at wrapping a line of text. Note that it isn't designed to work on multiple lines of text. It will attempt to split at convenient points within the required width and if that fails it will simply display what is there. All the text should be displayed with this method. You can also specify the linefeed characters as the last parameter. my $wrapped = wrap_text('a long string really', 10); # "a long\nstring\nreally" my $wrapped = wrap_text('a long string really', 10, "\r\n"); # "a long\r\nstring\r\nreally" string_to_id Makes a string safe to use as an HTML id. Converts all non safe characters to _. string_to_id('thuds-!this') # 'thuds__this' line_split Splits a string on line breaks. Accounts for all 3 types of line break, DOS, MAC and Unix. line_split("a\nb\r\nc") # qw/a b c/ missing_array_items Returns the list of items missing. $mandatory = [qw/a b c/]; $cols = [qw/a b d e f/]; missing_array_items($mandatory, $cols); # ['c'] not_blank Returns true if the string provided is not blank. not_blank('0') # 0 not_blank('') # 1 split_words Splits a list of words in a string. Looks for commas to split the list and strips whitespace. split_words('veh1,veh2,veh3') # qw/veh1 veh2 veh3/ mask_text Mask text field contents using a simple regex. mask_text('*', '(\d{4}).*(\d{3})', '456456564654654'); # '4564********654' Specify a fill character, a regex (as a string), and the text to mask out. This does not guard against rogue regexes. Capture the parts you expect to be retained. AUTHOR Colin Newell COPYRIGHT AND LICENSE This software is copyright (c) 2012 - 2016 by OpusVL. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.