From: Leon Timmermans Date: Sun, 6 Jan 2013 14:24:46 +0000 (+0100) Subject: Simplified "too complicated" handling X-Git-Tag: v0.001007~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2b3cd6e0dd68901e345fdc1831358cf91958be05;hp=fa713f7aff54ad7afd862617a5bad6b4384b55aa;p=p5sagit%2FSub-Exporter-Progressive.git Simplified "too complicated" handling --- diff --git a/lib/Sub/Exporter/Progressive.pm b/lib/Sub/Exporter/Progressive.pm index 3a773d5..670402c 100644 --- a/lib/Sub/Exporter/Progressive.pm +++ b/lib/Sub/Exporter/Progressive.pm @@ -5,19 +5,14 @@ use warnings; our $VERSION = '0.001007'; +use Carp 'croak'; use List::Util 'first'; sub import { my ($self, @args) = @_; my $inner_target = caller(0); - my ($TOO_COMPLICATED, $export_data) = sub_export_options($inner_target, @args); - - die <<'DEATH' if $TOO_COMPLICATED; -You are using Sub::Exporter::Progressive, but the features your program uses from -Sub::Exporter cannot be implemented without Sub::Exporter, so you might as well -just use vanilla Sub::Exporter -DEATH + my $export_data = sub_export_options($inner_target, @args); my $full_exporter; no strict; @@ -42,11 +37,15 @@ DEATH }; } +my $too_complicated = <<'DEATH'; +You are using Sub::Exporter::Progressive, but the features your program uses from +Sub::Exporter cannot be implemented without Sub::Exporter, so you might as well +just use vanilla Sub::Exporter +DEATH + sub sub_export_options { my ($inner_target, $setup, $options) = @_; - my $TOO_COMPLICATED = 0; - my @exports; my @defaults; my %tags; @@ -58,23 +57,18 @@ sub sub_export_options { for my $opt (keys %options) { if ($opt eq 'exports') { - $TOO_COMPLICATED = 1, last OPTIONS - if ref $options{exports} ne 'ARRAY'; - + croak $too_complicated if ref $options{exports} ne 'ARRAY'; @exports = @{$options{exports}}; - - $TOO_COMPLICATED = 1, last OPTIONS - if first { ref } @exports; + croak $too_complicated if first { ref } @exports; } elsif ($opt eq 'groups') { %tags = %{$options{groups}}; for my $tagset (values %tags) { - $TOO_COMPLICATED = 1 if first { /^-(?!all\b)/ || ref } @{$tagset}; + croak $too_complicated if first { /^-(?!all\b)/ || ref } @{$tagset}; } @defaults = @{$tags{default} || [] }; } else { - $TOO_COMPLICATED = 1; - last OPTIONS + croak $too_complicated; } } @{$_} = map { / \A [:-] all \z /x ? @exports : $_ } @{$_} for \@defaults, values %tags; @@ -83,12 +77,12 @@ sub sub_export_options { die join(', ', @errors) . " is not exported by the $inner_target module\n" if @errors; } - return $TOO_COMPLICATED, { + return { exports => \@exports, defaults => \@defaults, original => $options, tags => \%tags, - } + }; } 1;