$VERSION = '1.000008';
$VERSION = eval $VERSION;
+use Carp qw/croak/;
use File::Spec;
use IO::File;
use version 0.87;
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};
$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});
}
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 );
# 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));
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);
}
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;
last if defined $version;
}
- die $error unless defined $version;
+ croak $error unless defined $version;
return $version;
}