From: David Golden Date: Wed, 8 Feb 2012 16:53:49 +0000 (-0500) Subject: use croak instead of die X-Git-Tag: release_1.0.9~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6f3c7f28723bf0a04bbcdddb06db6abce27a467e;p=p5sagit%2FModule-Metadata.git use croak instead of die --- diff --git a/Changes b/Changes index ac7ff08..d50c571 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ - API of 'provides' changed to require a 'version' argument to future proof the function against CPAN Meta Spec changes + - Fatal errors now use 'croak' instead of 'die'; Carp added as + prerequisite 1.0.8 2012-02-07 22:30:00 - Adds 'provides' method to generate a CPAN META provides data structure diff --git a/Makefile.PL b/Makefile.PL index 9686e28..48818f9 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -8,6 +8,7 @@ WriteMakefile( NAME => 'Module::Metadata', VERSION_FROM => 'lib/Module/Metadata.pm', PREREQ_PM => { + 'Carp' => 0, 'version' => 0.87, }, ); diff --git a/lib/Module/Metadata.pm b/lib/Module/Metadata.pm index 189fbf9..8be2547 100644 --- a/lib/Module/Metadata.pm +++ b/lib/Module/Metadata.pm @@ -14,6 +14,7 @@ use vars qw($VERSION); $VERSION = '1.000008'; $VERSION = eval $VERSION; +use Carp qw/croak/; use File::Spec; use IO::File; use version 0.87; @@ -163,16 +164,16 @@ sub new_from_module { sub provides { my $class = shift; - die "provides() requires key/value pairs \n" if @_ % 2; + croak "provides() requires key/value pairs \n" if @_ % 2; my %args = @_; - die "provides() takes only one of 'dir' or 'files'\n" + croak "provides() takes only one of 'dir' or 'files'\n" if $args{dir} && $args{files}; - die "provides() requires a 'version' argument" + croak "provides() requires a 'version' argument" unless defined $args{version}; - die "provides() does not support version '$args{version}' metadata" + croak "provides() does not support version '$args{version}' metadata" unless grep { $args{version} eq $_ } qw/1.4 2/; $args{prefix} = 'lib' unless defined $args{prefix}; @@ -182,7 +183,7 @@ sub new_from_module { $p = $class->package_versions_from_directory($args{dir}); } else { - die "provides() requires 'files' to be an array reference\n" + croak "provides() requires 'files' to be an array reference\n" unless ref $args{files} eq 'ARRAY'; $p = $class->package_versions_from_directory($args{files}); } @@ -233,7 +234,7 @@ sub new_from_module { if ( $package eq $prime_package ) { if ( exists( $prime{$package} ) ) { - die "Unexpected conflict in '$package'; multiple versions found.\n"; + croak "Unexpected conflict in '$package'; multiple versions found.\n"; } else { $prime{$package}{file} = $mapped_filename; $prime{$package}{version} = $version if defined( $version ); @@ -385,7 +386,7 @@ sub _init { # class method sub _do_find_module { my $class = shift; - my $module = shift || die 'find_module_by_name() requires a package name'; + my $module = shift || croak 'find_module_by_name() requires a package name'; my $dirs = shift || \@INC; my $file = File::Spec->catfile(split( /::/, $module)); @@ -435,7 +436,7 @@ sub _parse_file { my $filename = $self->{filename}; my $fh = IO::File->new( $filename ) - or die( "Can't open '$filename': $!" ); + or croak( "Can't open '$filename': $!" ); $self->_parse_fh($fh); } @@ -592,15 +593,15 @@ sub _evaluate_version_line { warn "Error evaling version line '$eval' in $self->{filename}: $@\n" if $@; (ref($vsub) eq 'CODE') or - die "failed to build version sub for $self->{filename}"; + croak "failed to build version sub for $self->{filename}"; my $result = eval { $vsub->() }; - die "Could not get version from $self->{filename} by executing:\n$eval\n\nThe fatal error was: $@\n" + croak "Could not get version from $self->{filename} by executing:\n$eval\n\nThe fatal error was: $@\n" if $@; # Upgrade it into a version object my $version = eval { _dwim_version($result) }; - die "Version '$result' from $self->{filename} does not appear to be valid:\n$eval\n\nThe fatal error was: $@\n" + croak "Version '$result' from $self->{filename} does not appear to be valid:\n$eval\n\nThe fatal error was: $@\n" unless defined $version; # "0" is OK! return $version; @@ -658,7 +659,7 @@ sub _evaluate_version_line { last if defined $version; } - die $error unless defined $version; + croak $error unless defined $version; return $version; }