Data-Resolver

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    These functions help complying with the output API of a resolver, i.e.:

      * throw an exception when errors occur and the resolver was created
      with throw parameter set;

      * return just the content in scalar context;

      * return the content and additional metadata in list context.

    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');
          };
       }

  resolved

       return resolved($throw, $value, $meta_as_href);
       return resolved($throw, $value, %meta);

    Throw an exception if $throw is true and metadata have type set to
    error.

    Otherwise, return $value if called in scalar context.

    Otherwise, return a list with $value and a hash reference with the
    metadata.

  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 $throw is set, an
    exception is thrown.

  resolved_error_factory

       my $error_return = resolved_error_factory($throw);

    Wrap "resolved_error" with the specific value for $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.

  resolved_factory

       my $return = resolved_factory($throw);

    Wrap "resolved" with the specific value for $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.

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
    https://codeberg.org/polettix/Data-Resolver/issues.

AUTHOR

    Flavio Poletti <flavio@polettix.it>

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.



( run in 1.375 second using v1.01-cache-2.11-cpan-39bf76dae61 )