Data-Result

 view release on metacpan or  search on metacpan

lib/Data/Result.pm  view on Meta::CPAN

package Data::Result;

use Modern::Perl;
use Moo;
use MooX::Types::MooseLike::Base qw(:all);
use Carp qw(croak);
use Scalar::Util qw(blessed);
use boolean;
use namespace::clean;

use overload
  fallback=>1,
  '""'=>sub { $_[0]->msg },
  bool=>sub { $_[0]->is_true },
;

our $VERSION='1.0003';

=head1 NAME

Data::Result - Handling true and false in a better way!

=head1 SYNOPSIS

  use Modern::Perl;
  use Data::Result;

  # just true 
  my $result=Data::Result->new(is_true=>0);
  if($result) {
    print "Yup its true!\n";
  }

  # True with data
  $result=Data::Result->new(is_true=>1,data=>'Yup This is true!');
  if($result) {
    print $result->data,"\n";
  }

  # just flase
  $result=Data::Result->new(is_true=>0);
  if($result) {
    print $result->data,"\n";
  } else {
    print "well, something went wrong!\n";
  }

  # handle false, but give us an error!
  $result=Data::Result->new(is_true=>0,msg=>'this is our message');
  if($result) {
    print $result->data,"\n";
  } else {
    print "$result\n";
  }

=head1 DESCRIPTION

Handling true and false isn't always enough.  This alows true and false to encapsulate things as a simple state.

=cut

# This method runs after the new constructor
sub BUILD {
  my ($self)=@_;
}

# this method runs before the new constructor, and can be used to change the arguments passed to the module
around BUILDARGS => sub {
  my ($org,$class,@args)=@_;
  
  return $class->$org(@args);
};


=head1 Object Constructor Arguments

Data::Result provides the following constructor arguments

Required arguments:

  is_true: true or fale
    # if not blessed it will be converted to a boolean true or false object

Optional arguments

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.323 second using v1.00-cache-2.02-grep-82fe00e-cpan-f5108d614456 )