The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

ReturnValue - A structured return value for failure or success

SYNOPSIS

        use ReturnValue;

        sub do_something {
                ...;

                return ReturnValue->error(
                        value       => $your_usual_error_value,
                        description => 'Some longer description',
                        tag         => 'short_value'
                        ) if $failed;

                return ReturnValue->success(
                        value       => $your_usual_return_value,
                        description => 'Some longer description',
                        tag         => 'short_value'
                        ) unless $failed;
                }


        my $result = do_something();
        if( $result->is_error ) {
                ...; # do error stuff
                }

        my $result = do_something_else();
        for( $result->tag ) {
                when( 'tag1' ) { ... }
                when( 'tag2' ) { ... }

                }

DESCRIPTION

The ReturnValue class provides a very simple wrapper around a value so you can tell if it's a success or failure without taking pains to examine the particular value. Instead of using exceptions, you inspect the class of the object you get back. Errors and successes flow through the same path.

This isn't particularly interesting for success values, but can be helpful with multiple ways to describe an error.

success

Create a success object

error

Create an error object

value

The value that you'd normally return. This class doesn't care what it is. It can be a number, string, or reference. It's up to your application to figure out how you want to do that.

description

A long description of the return values,

tag

A short tag suitable for switching on in a given, or something similar.

success_type

Returns the class for success objects

error_type

Returns the class for error objects

is_success

Returns true is the result represents a success

is_error

Returns true is the result represents a success

TO DO

SEE ALSO

SOURCE AVAILABILITY

This source is in Github:

        http://github.com/perlreview/returnvalue/

AUTHOR

brian d foy, <bdfoy@cpan.org>

COPYRIGHT AND LICENSE

Copyright © 2013-2019, brian d foy <bdfoy@cpan.org>. All rights reserved.

You may redistribute this under the terms of the Artistic License 2.0.