Skip to content

Commit

Permalink
remove Exception::Class
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Apr 19, 2015
1 parent d422cbb commit d0e6504
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
1 change: 0 additions & 1 deletion cpanfile
Expand Up @@ -10,7 +10,6 @@ requires 'Module::CPANfile', 0.9031;

requires 'Try::Tiny', 0.09;
requires 'parent', 0.223;
requires 'Exception::Class', 1.32;
requires 'Getopt::Long', 2.39;
requires 'Moo', 1.002;
requires 'Path::Tiny', 0.033;
Expand Down
46 changes: 38 additions & 8 deletions lib/Carton/Error.pm
@@ -1,12 +1,42 @@
package Carton::Error;
use strict;
use Exception::Class (
'Carton::Error',
'Carton::Error::CommandNotFound' => { isa => 'Carton::Error' },
'Carton::Error::CommandExit' => { isa => 'Carton::Error', fields => [ 'code' ] },
'Carton::Error::CPANfileNotFound' => { isa => 'Carton::Error' },
'Carton::Error::SnapshotParseError' => { isa => 'Carton::Error', fields => [ 'path' ] },
'Carton::Error::SnapshotNotFound' => { isa => 'Carton::Error', fields => [ 'path' ] },
);
use overload '""' => sub { $_[0]->error };
use Carp;

sub throw {
my($class, @args) = @_;
die $class->new(@args);
}

sub rethrow {
die $_[0];
}

sub new {
my($class, %args) = @_;
bless \%args, $class;
}

sub error {
$_[0]->{error} || ref $_[0];
}

package Carton::Error::CommandNotFound;
use parent 'Carton::Error';

package Carton::Error::CommandExit;
use parent 'Carton::Error';
sub code { $_[0]->{code} }

package Carton::Error::CPANfileNotFound;
use parent 'Carton::Error';

package Carton::Error::SnapshotParseError;
use parent 'Carton::Error';
sub path { $_[0]->{path} }

package Carton::Error::SnapshotNotFound;
use parent 'Carton::Error';
sub path { $_[0]->{path} }

1;

0 comments on commit d0e6504

Please sign in to comment.