Data-Resolver
view release on metacpan or search on metacpan
lib/Data/Resolver.pod view on Meta::CPAN
=item *
return the content and additional metadata in list context.
=back
A typical way of using these function is like this:
sub resolver_for_whatever (%args) {
my $OK = resolved_factory($args{throw});
my $KO = resolved_error_factory($args{throw});
return sub ($key, $type = 'xxx') {
return $KO->(400 => 'Wrong inputs!') if $some_error;
return $OK->($data, type => 'data');
};
}
=head3 B<< resolved >>
return resolved($throw, $value, $meta_as_href);
return resolved($throw, $value, %meta);
Throw an exception if C<$throw> is I<true> and metadata have C<type> set
to C<error>.
Otherwise, return C<$value> if called in scalar context.
Otherwise, return a list with C<$value> and a hash reference with the
metadata.
=head3 B<< resolved_error >>
return resolved_error($throw, $code, $message, $meta);
return resolved_error($throw, $code, $message, %meta);
If an error has to be returned, this is a shorthand to integrate the
optional metadata with a code and a message. If C<$throw> is set, an
exception is thrown.
=head3 B<< resolved_error_factory >>
my $error_return = resolved_error_factory($throw);
Wrap L</resolved_error> with the specific value for C<$throw>. This can
be useful because whether a resolver should throw exceptions or not is
usually set at resolver creation time, so it makes sense to wrap this
characteristic.
=head3 B<< resolved_factory >>
my $return = resolved_factory($throw);
Wrap L</resolved> with the specific value for C<$throw>. This can be
useful because whether a resolver should throw exceptions or not is
usually set at resolver creation time, so it makes sense to wrap this
characteristic.
=head1 BUGS AND LIMITATIONS
Minimum perl version 5.24 because reasons (it's been around since 2016
and signatures just make sense).
Report bugs through Codeberg (patches welcome) at
L<https://codeberg.org/polettix/Data-Resolver/issues>.
=head1 AUTHOR
Flavio Poletti <flavio@polettix.it>
=head1 COPYRIGHT AND LICENSE
Copyright 2023 by Flavio Poletti <flavio@polettix.it>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=cut
( run in 0.843 second using v1.01-cache-2.11-cpan-39bf76dae61 )