NAME

MVC::Neaf::Util - Some static functions for Not Even A Framework

DESCRIPTION

This is utility class. Nothing to see here unless one intends to work on MVC::Neaf itself.

EXPORT

This module optionally exports anything it has.

caller_info()

Returns first caller(n) that is not inside MVC::Neaf itself.

This is implemented inside Carp::shortmess but we can't rely on Carp's internals.

canonize_path( path, want_slash )

Convert '////fooo//bar/' to '/foo/bar' and '//////' to either '' or '/'.

check_path

@array = check_path @array

Check a list of path for bad characters in path spec. Will issue a warning if something strange is present. Most notably, forbids : in order to allow for future /my/path/:param

Returns unmodified list. This as well as prototype is done so for simpler integration with map.

decode_b64

Decode unpadded URL-friendly base64. Also works on normal one.

See "decode_base64url" in MIME::Base64.

encode_b64

Encode data as unpadded URL-friendly base64 - with - for 62 and _ for 63. = signs are removed.

See "encode_base64url" in MIME::Base64.

extra_missing

extra_missing( \%input, \%allowed, \@required )

Dies if %input doesn't pass validation. Only definedness is checked.

http_date

Return a date in format required by HTTP standard for cookies and cache expiration.

Expires=Wed, 13 Jan 2021 22:23:01 GMT;

make_getters

Create dumb accessors in the calling class from hash. Keys are method names.

Key in the object is hash value if it's an identifier, or just method name otherwise:

package My::Class;

# (declare constructor somehow)
make_getters (
    foo => bar,
    baz => 1,
    quux => '',
);

# ...

my $obj = My::Class->new;

$obj->foo;  # {bar}
$obj->baz;  # {baz}
$obj->quux; # {quux}

maybe_list

maybe_list( $value, @defaults )

If $value is undef, return a copy of \@defaults.

If $value is a list, return a copy of it.

Otherwise, return [ $value ].

path_prefixes ($path)

List ('', '/foo', '/foo/bar') for '/foo/bar'

rex( $string || qr/r.e.g.e.x/ )

Convert string or regex to an anchored regex.

run_all( [CODE, ...], @args )

Run all subroutines in array. Exceptions not handled. Return nothing.

run_all_nodie( [CODE, ...], $on_error, @args )

Run all subroutines in array, even if some die.

Execute on_error in such cases.

Return number of failed callbacks.

supported_methods

JSON()

Because JSON::MaybeXS is not available on all systems, try to load it or emulate it.

encode_json

decode_json

These two are reexported from whatever JSON module we were lucky enough to load.

data_fh($n)

Get DATA filehandle in the calling package $n levels up the stack, together with the file name (so that we don't read the same __DATA__ twice).

bare_html_escape( $dangerous )

A crude html-entities escaper. Should be replaced by something real.

LICENSE AND COPYRIGHT

This module is part of MVC::Neaf suite.

Copyright 2016-2023 Konstantin S. Uvarin khedin@cpan.org.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.