=pod =encoding utf8 =head1 NAME Mojolicious::Plugin::MoreUtilHelpers - Methods to format, count, sanitize, etc... =head1 SYNOPSIS # Mojolicious $self->plugin('MoreUtilHelpers', %defaults); # Mojolicious::Lite plugin 'MoreUtilHelpers', %defaults; $self->count(10, 'user'); # 10 users $self->count([User->new]); # 1 user $self->paragraphs($text); #
line 1
line 2
... $self->maxwords('a, b, c', 2) # a, b... $self->sanitize($html); # remove all HTML # keep andtags $self->sanitize($html, tags => ['a','p']); # future calls to param($name[n]) return trimmed values $self->trim_param(@names); =head1 METHODS Defaults can be set for certain methods when the plugin is loaded. $self->plugin('MoreUtilHelpers', maxwords => { omit => ' [snip]' }, sanitize => { tags => ['code', 'pre', 'a'] }); By default and, unless stated otherwise, no defaults are set. See the method docs for more info. =head2 count $self->count(10, 'user'); # 10 users $self->count([User->new]); # 1 user $self->count([User->new], 'Luser'); # 1 Luser Use the singular or plural form of the word based on the number given by the first argument. If a non-empty array of objects are given the lowercase form of the package's basename is used. =head2 maxwords $self->maxwords($str, $n); $self->maxwords($str, $n, '…'); Truncate C<$str> after C<$n> words. If C<$str> has more than C<$n> words traling punctuation characters are stripped from the C<$n>th word and C<'...'> is appended. An alternate ommision character can be given as the third option. =head3 Setting Defaults $self->plugin('MoreUtilHelpers', maxwords => { omit => ' [snip]', max => 20 }); =head2 paragraphs $self->paragraphs($text); Wrap lines seperated by empty C<\r\n> or C<\n> lines in HTML paragraph tags (C