[Rt-devel] Re: [PATCH] DBIx::SB::Record.pm aliases cleanup and docs

Ruslan U. Zakirov Ruslan.Zakirov at miet.ru
Thu May 5 13:56:23 EDT 2005


Tatsuhiko Miyagawa wrote:
> On 5/6/05, Ruslan U. Zakirov <Ruslan.Zakirov at miet.ru> wrote:
> 
>>>Do you want _primary_key here?
 >>
>>Yes. I've wrote fix for this. Attached.
 >
> Thanks, applied.
> 
>>Another problem I see is methods with upper case sequences in name, like
>>special subs(AUTOLOAD, DESTROY) or normal methods like ACL, ID. It's not
>>showstopper for DBIx::SB, but "bug"/"undocumented feature" in the pragma.
> 
> Patches (incl. documentation) welcome :)

Attached patch that fix all corner cases I see and adds docs. Applies 
against clean 0.01.

Also added note about case when user wants add nocap aliases in the 
caller(0) package. I think that this note would be enough and don't 
think that this case should be fixed.

--
Regards, Ruslan.
-------------- next part --------------
diff -ru capitalization-0.01/capitalization.pm capitalization-0.01-cub1/capitalization.pm
--- capitalization-0.01/capitalization.pm	2003-02-10 02:14:55.000000000 +0000
+++ capitalization-0.01-cub1/capitalization.pm	2005-04-12 17:47:03.590000000 +0000
@@ -31,7 +31,8 @@
 sub nocap {
     my $method = shift;
     $method =~ s/(?<=[a-z])([A-Z]+)/"_" . lc($1)/eg;
-    lcfirst $method;
+    $method =~ tr/A-Z/a-z/;
+    return $method;
 }
 
 sub mod2file {
@@ -65,6 +66,27 @@
 
 capitalization.pm allows you to use familiar style on method naming.
 
+=head1 RULES
+
+=over 1
+
+=item Lower case character followed by upper case sequence would be
+splitted with C<_> and upper case sequence would be lower cased.
+Example: C<fooBar> would be C<foo_bar>.
+
+=item All other upper case characters would be lower cased.
+Examples: C<FOOs> would be C<foos>, C<_Foo> would be C<_foo>.
+
+=back
+
+=head1 CAVEATS
+
+=head2 C<no capitalization __PACKAGE__;>
+
+If you want use capitalization pragma in module and add lower case
+API in the module itself, then you should use pragma after all subs
+are defined.
+
 =head1 AUTHOR
 
 Tatsuhiko Miyagawa E<lt>miyagawa at bulknews.netE<gt>
diff -ru capitalization-0.01/t/01_capital.t capitalization-0.01-cub1/t/01_capital.t
--- capitalization-0.01/t/01_capital.t	2003-02-10 02:14:55.000000000 +0000
+++ capitalization-0.01-cub1/t/01_capital.t	2005-04-12 17:20:38.170000000 +0000
@@ -1,10 +1,11 @@
 use strict;
-use Test::More tests => 1;
+use Test::More tests => 2;
 
 use lib qw(t/lib);
 no capitalization qw(Module::LikeJava);
 
 my $m = Module::LikeJava->new;
-can_ok $m, qw(foo_and_bar bar_and_baz fooAndBar BarAndBAZ);
+can_ok $m, qw(fooAndBar   BarAndBAZ   _Bar FOO FOObar);
+can_ok $m, qw(foo_and_bar bar_and_baz _bar foo foobar);
 
 
diff -ru capitalization-0.01/t/lib/Module/LikeJava.pm capitalization-0.01-cub1/t/lib/Module/LikeJava.pm
--- capitalization-0.01/t/lib/Module/LikeJava.pm	2003-02-10 02:14:55.000000000 +0000
+++ capitalization-0.01-cub1/t/lib/Module/LikeJava.pm	2005-04-12 17:19:45.760000000 +0000
@@ -7,4 +7,10 @@
 
 sub BarAndBAZ { }
 
+sub _Bar { }
+
+sub FOO { }
+
+sub FOObar { }
+
 1;


More information about the Rt-devel mailing list