summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Fredric <kentfredric@gmail.com>2011-10-25 05:27:23 +1300
committerKent Fredric <kentfredric@gmail.com>2011-10-25 07:23:18 +1300
commitaf3f201ecb8868ab0ba4013d5180f8bbfbfbbaba (patch)
tree87a74d363d769be6c8dbd1a99083219e16b01947 /scripts/lib
parent[Scripts/package_log.pl] refactor guts of package_log.pl (diff)
downloadperl-overlay-af3f201ecb8868ab0ba4013d5180f8bbfbfbbaba.tar.gz
perl-overlay-af3f201ecb8868ab0ba4013d5180f8bbfbfbbaba.tar.bz2
perl-overlay-af3f201ecb8868ab0ba4013d5180f8bbfbfbbaba.zip
[scripts] fix colorcarp code, normalize body
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/colorcarp.pm54
-rw-r--r--scripts/lib/env/gentoo/perl_experimental.pm2
2 files changed, 38 insertions, 18 deletions
diff --git a/scripts/lib/colorcarp.pm b/scripts/lib/colorcarp.pm
index bc878eb28..fa18ab5b0 100644
--- a/scripts/lib/colorcarp.pm
+++ b/scripts/lib/colorcarp.pm
@@ -16,31 +16,51 @@ package colorcarp;
=cut
-use Sub::Exporter -setup => {
- exports => [ carper => \&build_carper, ],
- collectors => [ defaults => \&defaults_collector ],
+use Sub::Exporter -setup => {
+ exports => [ carper => \&build_carper, ],
+ collectors => [ defaults => \&defaults_collector ],
};
-sub defaults_collector {
- my ( $collection, $config ) = @_;
- $collection->{attributes} ||= [];
- if( @{ $collection->{attributes} } ){
- require Term::ANSIColor;
- return if not Term::ANSIColor::colorvalid(@{ $collection->{attributes} });
+
+sub _lint_opts {
+ my ( $hash, $set_unset ) = @_;
+
+ if ( $set_unset and ( not exists $hash->{attributes} or not defined $hash->{attributes} ) ) {
+ $hash->{attributes} = [];
+ }
+
+ #use Data::Dump;
+ #Data::Dump::pp( \@_ );
+ if ( exists $hash->{attributes} and defined $hash->{attributes} ) {
+ not ref $hash->{attributes} eq 'ARRAY' and do { require Carp; Carp::confess('attributes is not an arrayref') }
}
- $collection->{method} ||= 'confess'
- if( not grep { $_ eq $collection->{method} } qw( confess carp cluck croak ) ){
- return;
+ if ( $set_unset and ( not exists $hash->{method} or not defined $hash->{method} ) ) {
+ $hash->{method} = 'confess';
}
+ if ( exists $hash->{method} and defined $hash->{method} ) {
+
+ if ( not grep { $_ eq $hash->{method} } qw( confess carp cluck croak ) ) {
+ require Carp;
+ Carp::confess('method is not one of confess,carp,cluck,croak');
+ }
+ }
+}
+
+sub defaults_collector {
+ my ( $collection, $config ) = @_;
+ _lint_opts( $collection, 1 );
return 1;
}
sub build_carper {
- my ( $class, $name, $args , $col ) = @_;
- my $attributes = ( $args->{attributes} || [] );
- unshift @$attributes, @{ $col->{defaults}->{attributes} };
-
+ my ( $class, $name, $args, $col ) = @_;
+ _lint_opts( $col->{defaults}, 1 );
+ _lint_opts( $args, 0 );
+
+ my $attributes = [ @{ $col->{defaults}->{attributes} || [] }, @{ $args->{attributes} || [] } ];
+ my $method = $args->{method} || $col->{defaults}->{method} || 'ćonfess';
+
require Carp;
- my $call = Carp->can( $args->{method} || $col->{defaults}->{method} );
+ my $call = Carp->can($method);
return sub {
require Term::ANSIColor;
diff --git a/scripts/lib/env/gentoo/perl_experimental.pm b/scripts/lib/env/gentoo/perl_experimental.pm
index dbc9ff060..ea009241c 100644
--- a/scripts/lib/env/gentoo/perl_experimental.pm
+++ b/scripts/lib/env/gentoo/perl_experimental.pm
@@ -37,7 +37,7 @@ sub _build_root {
}
use colorcarp
- carper => { attributes => [qw( red on_white )], method => 'confess' , -as => 'redconfess' };
+ carper => { attributes => [qw( red on_white )] , -as => 'redconfess' };
sub check_script {
my ( $self, $scriptname ) = @_;