[Bps-public-commit] r17606 - in Text-Naming-Convention: lib/Text/Naming

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed Jan 7 02:34:50 EST 2009


Author: sunnavy
Date: Wed Jan  7 02:34:50 2009
New Revision: 17606

Modified:
   Text-Naming-Convention/lib/Text/Naming/Convention.pm
   Text-Naming-Convention/t/01.api.t

Log:
automatically renaming $_ if without arguments when renaming

Modified: Text-Naming-Convention/lib/Text/Naming/Convention.pm
==============================================================================
--- Text-Naming-Convention/lib/Text/Naming/Convention.pm	(original)
+++ Text-Naming-Convention/lib/Text/Naming/Convention.pm	Wed Jan  7 02:34:50 2009
@@ -122,12 +122,25 @@
 
 if the convention is the same as the name, just return the name.
 
+if without arguments and $_ is defined and it's not a reference, renaming $_
+
 
 =cut
 
 sub renaming {
-    my $name        = shift;
-    my $option      = shift;
+
+    my ($name, $option);
+    if ( scalar @_ ) {
+        $name        = shift;
+        $option      = shift;
+    }
+    elsif ( defined $_ && ! ref $_ ) {
+        $name = $_;
+    }
+    else {
+        return
+    }
+
     my $convention  = $_default_convention;
 
     if ( $option && ref $option eq 'HASH' ) {

Modified: Text-Naming-Convention/t/01.api.t
==============================================================================
--- Text-Naming-Convention/t/01.api.t	(original)
+++ Text-Naming-Convention/t/01.api.t	Wed Jan  7 02:34:50 2009
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 57;    # last test to print
+use Test::More tests => 61;    # last test to print
 
 use Text::Naming::Convention qw/naming renaming default_convention
   default_keep_uppers/;
@@ -130,3 +130,14 @@
 is( renaming('UpdateCFs'),
     'update_cfs',
     'renaming UpdateCFs with default convention will get update_cfs' );
+
+# if without argument, renaming $_
+$_ = 'SirGombrich';
+is( renaming, 'sir_gombrich', 'renaming $_ if without arguments' );
+$_ = [];
+is( renaming, undef, 'return undef if without arguments and $_ is ref' );
+$_ = '';
+is( renaming, '', 'return empty string if without arguments and $_ is empty' );
+undef $_;
+is( renaming, undef, 'return undef if without arguments and $_ is undef' );
+



More information about the Bps-public-commit mailing list