NAME
MVC::Neaf::Util::Container - path & method based container for Not Even A Framework
DESCRIPTION
This is utility class. Nothing to see here unless one intends to work on MVC::Neaf itself.
This class can hold multiple entities addressed by paths and methods and extract them in the needed order.
SYNOPSIS
my
$c
= MVC::Neaf::Util::Container->new;
$c
->store(
"foo"
,
path
=>
'/foo'
,
method
=>
'GET'
);
$c
->store(
"bar"
,
path
=>
'/foo/bar'
,
exclude
=>
'/foo/bar/baz'
);
$c
->fetch(
path
=>
"/foo"
,
method
=>
'GET'
);
# foo
$c
->fetch(
path
=>
"/foo/bar"
,
method
=>
'GET'
);
# foo bar
$c
->fetch(
path
=>
"/foo/bar"
,
method
=>
'POST'
);
# qw(bar) - 'foo' limited to GET only
$c
->fetch(
path
=>
"/foo/bar/baz"
,
method
=>
'GET'
);
# qw(foo) - 'bar' excluded
ATTRIBUTES
exclusive
Only store one item per (path,method) pair, and fail loudly in case of conflicts.
METHODS
store
store(
$data
,
%spec
)
Store $data in container. Spec may include:
- path - single path or list of paths, '/' assumed if none.
- method - name of method or array of methods. By default, all methods supported by Neaf.
- exclude - single path or list of paths. None by default.
- prepend - if true, prepend to the list instead of appending.
- tentative (exclusive container only) - if true, don't override existing declarations, and don't complain when overridden.
- override (exclusive container only) - if true, override any preexisting content.
store_check_conflict
store_check_conflict(
path
=> ...,
method
=> ... )
Check that no previous declarations conflict with the new one.
This is only if exclusive was specified.
list_methods
Returns methods currently in the storage.
list_paths
Returns paths for given method, or all if no method given.
fetch
fetch(
%spec
)
Return all matching previously stored objects, from shorter to longer paths, in order of addition.
Spec may include:
fetch_last
Same as fetch(), but only return the last (last added & longest path) element.
fetch_raw
Same as fetch(), but return additional info instead of just stored item:
{
data
=>
$your_item_here
,
path
=>
$all_the_paths
,
method
=>
$list_of_methods
,
...
}
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.