The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

results::wrap - wrap a method call in a Result

SYNOPSIS

Assuming that $object->foo( @args ) is a method call which might return a value or throw an exception, you can convert it to an ok/err Result using:

use results::wrap;

my $result = $object->results::wrap::foo( @args );

Or:

use results::wrap;

my $result = $object->results::wrap( foo => @args );

Or:

use results::wrap;

my $result = results::wrap { $object->foo( @args ) };

DESCRIPTION

This module uses AUTOLOAD to provide a Result wrapper around any method call.

It also provides a results::wrap sub which can be either passed a list of $invocant, $method, @args or a single coderef.

results::wrap is conveniently prototyped with (&) to that it can be called with a block.

my $result = results::wrap {
  if ( $failing_condition ) {
    die "Error";
  }
  else {
    return "Value";
  }
};

BUGS

Please report any bugs to https://github.com/tobyink/p5-results/issues.

SEE ALSO

results.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE

This software is copyright (c) 2022 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.