package Venus::Role::Tryable;

use 5.018;

use strict;
use warnings;

use Venus::Role 'with';


sub try {
  my ($self, $callback, @args) = @_;

  require Venus::Try;

  my $try = Venus::Try->new(invocant => $self, arguments => [@args]);

  return $try if !$callback;

  return $try->call($callback);


sub EXPORT {


=head1 NAME

Venus::Role::Tryable - Tryable Role



Tryable Role for Perl 5



  package Example;

  use Venus::Class 'with';
  use Venus 'raise';

  with 'Venus::Role::Tryable';

  sub test {
    raise 'Example::Error';

  package main;

  my $example = Example->new;

  # $example->try('test');



This package modifies the consuming package and provides a mechanism for
handling potentially volatile routines.


=head1 METHODS

This package provides the following methods:


=head2 try

  try(Str | CodeRef $method, Any @args) (Try)

The try method returns a L<Venus::Try> object having the invocant, callback,
arguments pre-configured. This method supports dispatching, i.e. providing a
method name and arguments whose return value will be acted on by this method.

I<Since C<0.01>>

=over 4

=item try example 1

  package main;

  my $example = Example->new;

  my $try = $example->try('test');

  # my $value = $try->result;