[Rt-devel] Re: [PATCH] DBIx::SB::Record.pm aliases cleanup and
docs [ver2]
Ruslan U. Zakirov
Ruslan.Zakirov at miet.ru
Fri May 6 06:14:14 EDT 2005
Jesse Vincent wrote:
>
>
> On Thu, Apr 07, 2005 at 05:01:44PM +0400, Ruslan U. Zakirov wrote:
>
>>Forgot about attachment :)
>>
>>Ruslan U. Zakirov wrote:
>>
>>> Hello.
>>>Attached patch add missing aliases and some words that such aliases exist.
>>>
>
>
>
> What do you think about switching to use miyagawa's capitalization.pm
> for this function instead?
Hello, Jesse.
Attach two solutions and three patches. Just for fun! :)
1) via capitalization.pm 0.03
nocap_via_pragma.patch
This patch has docs that should be added in any case.
2) via scrip made aliases
Wrote small script(fix_aliases.pl) that reads code from STDIN and output
code with aliases to STDOUT.
> cat SearchBuilder.pm | perl fix_aliases.pl >tmp && mv tmp
SearchBuilder.pm
3) test file that check if all subs has aliases
nocap_test.patch
Can be used with both solutions to check API consistency.
And last prefered solution: deprecate all that lower case alias crap and
suggest to use capitalization.pm 0.03 instead :)
Choose any ;)
--
Regards, Ruslan.
>
>
>>>--
>>>Best regards, Ruslan.
>>>
>>
-------------- next part --------------
==== Patch <-> level 1
Source: [No source]
Target: fac90757-c5f0-0310-a953-bfb799f65e4e:/DBIx-SearchBuilder/local:242
Log:
nocap via capitalization pragma
=== Makefile.PL
==================================================================
--- Makefile.PL (revision 242)
+++ Makefile.PL (patch - level 1)
@@ -7,7 +7,8 @@
requires('Want');
requires('Encode');
requires('Class::ReturnValue', 0.40);
-requires( 'Cache::Simple::TimedExpiry' => '0.21');
+requires('Cache::Simple::TimedExpiry' => '0.21');
+requires('capitalization', 0.03);
build_requires('Test::More');
&Makefile->write;
=== SearchBuilder/Record.pm
==================================================================
--- SearchBuilder/Record.pm (revision 242)
+++ SearchBuilder/Record.pm (patch - level 1)
@@ -8,6 +8,7 @@
use Class::ReturnValue;
+
# {{{ Doc
=head1 NAME
@@ -337,6 +338,10 @@
ever else I think of.
+=head1 METHODS NAMING
+
+All methods has lower case aliases, '_' is used to distinguish words.
+For example method C<_PrimaryKeys> has alias C<_primary_keys>.
=head1 METHODS
@@ -375,9 +380,9 @@
=cut
-*Id = \&id;
-sub id {
+
+sub Id {
my $pkey = $_[0]->_PrimaryKey();
$_[0]->{'values'}->{$pkey};
}
@@ -394,7 +399,7 @@
-*primary_keys = \&PrimaryKeys;
+
sub PrimaryKeys {
my $self = shift;
my %hash = map { $_ => $self->{'values'}->{$_} } @{$self->_PrimaryKeys};
@@ -501,7 +506,7 @@
=cut
-*_accessible = \&_Accessible;
+
sub _Accessible {
my $self = shift;
my $attr = shift;
@@ -614,7 +619,7 @@
=cut
-*__value = \&__Value;
+
sub __Value {
my $self = shift;
my $field = lc(shift);
@@ -642,7 +647,7 @@
=cut
-*_value = \&_Value;
+
sub _Value {
my $self = shift;
return ($self->__Value(@_));
@@ -660,7 +665,7 @@
=cut
-*_set = \&_Set;
+
sub _Set {
my $self = shift;
return ($self->__Set(@_));
@@ -668,7 +673,7 @@
-*__set = \&__Set;
+
sub __Set {
my $self = shift;
@@ -789,7 +794,7 @@
#TODO: Implement _Validate.
-*_validate = \&_Validate;
+
sub _Validate {
my $self = shift;
my $field = shift;
@@ -926,7 +931,7 @@
=cut
-*load = \&Load;
+
sub Load {
my $self = shift;
# my ($package, $filename, $line) = caller;
@@ -944,8 +949,8 @@
=cut
-*load_by_col = \&LoadByCol;
+
sub LoadByCol {
my $self = shift;
my $col = shift;
@@ -970,7 +975,7 @@
=cut
-*load_by_cols = \&LoadByCols;
+
sub LoadByCols {
my $self = shift;
my %hash = (@_);
@@ -1013,7 +1018,7 @@
=cut
-*load_by_id = \&LoadById;
+
sub LoadById {
my $self = shift;
my $id = shift;
@@ -1034,8 +1039,8 @@
=cut
-*load_by_primary_keys = \&LoadByPrimaryKeys;
+
sub LoadByPrimaryKeys {
my ($self, $data) = @_;
@@ -1063,8 +1068,8 @@
=cut
-*load_from_hash = \&LoadFromHash;
+
sub LoadFromHash {
my $self = shift;
my $hashref = shift;
@@ -1087,9 +1092,9 @@
=cut
-*load_from_sql = \&LoadFromSQL;
+
sub _LoadFromSQL {
my $self = shift;
my $QueryString = shift;
@@ -1143,8 +1148,8 @@
=cut
-*create = \&Create;
+
sub Create {
my $self = shift;
my %attribs = @_;
@@ -1229,8 +1234,8 @@
=cut
-*table = \&Table;
+
sub Table {
my $self = shift;
if (@_) {
@@ -1249,7 +1254,7 @@
=cut
-*_handle = \&_Handle;
+
sub _Handle {
my $self = shift;
if (@_) {
@@ -1260,6 +1265,7 @@
# }}}
+no capitalization __PACKAGE__;
1;
=== SearchBuilder.pm
==================================================================
--- SearchBuilder.pm (revision 242)
+++ SearchBuilder.pm (patch - level 1)
@@ -31,6 +31,11 @@
This module provides an object-oriented mechanism for retrieving and updating data in a DBI-accesible database.
+=head1 METHODS NAMING
+
+All methods has lower case aliases, '_' is used to distinguish words.
+For example method C<RedoSearch> has alias C<redo_search>.
+
=head1 METHODS
=cut
@@ -397,8 +402,8 @@
=cut
-*next = \&Next;
+
sub Next {
my $self = shift;
my @row;
@@ -430,7 +435,7 @@
=cut
-*goto_first_item = \&GotoFirstItem;
+
sub GotoFirstItem {
my $self = shift;
$self->GotoItem(0);
@@ -1341,7 +1346,7 @@
=cut
-*count = \&Count;
+
sub Count {
my $self = shift;
@@ -1604,6 +1609,7 @@
# }}}
+no capitalization __PACKAGE__;
1;
__END__
==== BEGIN SVK PATCH BLOCK ====
Version: svk 0.29 (linux)
eJyFlF1MHFUUx2/i7NKuiIb4/VA3OrSasDBz78zsDLQrUChSCiFQrCmmmztz78DYYWedHRDs1HiG
gtT61djEB0h88NkHX4oh0TTGGmKJ+KQmPpiamMaa+OpLk3p3lyZQm5rMw9ycc/7nnN+55x4Jj3d2
qXGhoMSyqsRjLw92dIzQyJlqESfZiDnzoiCU9djns9yXSewHk7IWl+g0F9aIhpM8KhRUEWzWg/tq
AXdEtKqGTaOgVJGtmlgxCjmX1VjvMuIuHHcRERqrwhiUeakYBkEkkm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zHhMxnrc3tszMJfbvXG+yOfXN00mRuxSx1Lyej7n
6K6SU4iq5Kilk5wtxm5ZrqFzjf8LKqfvQA==
==== END SVK PATCH BLOCK ====
-------------- next part --------------
#!/usr/bin/perl -w
use strict;
use vars qw(@SPEC_METHODS);
my @SPEC_METHODS = qw(AUTOLOAD DESTROY CLONE);
my $text;
{
local $/;
$text = <STDIN>;
}
while( $text =~ m/(^sub\s+([_a-zA-Z]+)\s*\n*\s*\{)/msg ) {
my ($def_str, $method) = ($1, $2);
my $alias = nocap( $method );
next if $method eq $alias;
my $pos = pos $text;
# pos($text) = 0;
if( $text =~ /^\*\Q$alias\E\s*=\s*\\\&\Q$method\E;$/m ) {
pos( $text ) = $pos;
next;
}
substr( $text, $pos - length $def_str, 0 ) = '*'. $alias .' = \&'. $method .";\n";
}
print $text;
sub nocap
{
my $method = shift;
return $method if grep( { $_ eq $method } @SPEC_METHODS );
$method =~ s/(?<=[a-z])([A-Z]+)/"_" . lc($1)/eg;
return lc($method);
}
-------------- next part --------------
==== Patch <-> level 1
Source: [No source]
Target: fac90757-c5f0-0310-a953-bfb799f65e4e:/DBIx-SearchBuilder/local/t:233
Log:
nocap test file
=== 01nocap_api.t
==================================================================
--- 01nocap_api.t (revision 233)
+++ 01nocap_api.t (patch - level 1)
@@ -0,0 +1,38 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Test::More;
+BEGIN { require "t/utils.pl" }
+
+use vars qw(@SPEC_METHODS @MODULES);
+my @SPEC_METHODS = qw(AUTOLOAD DESTROY CLONE);
+my @MODULES = qw(DBIx::SearchBuilder DBIx::SearchBuilder::Record);
+
+unless( eval { require Devel::Symdump } ) {
+ plan skip_all => 'Devel::Symdump is not installed';
+} else {
+ plan tests => scalar @MODULES;
+}
+
+foreach my $mod( @MODULES ) {
+ eval "require $mod";
+ my $dump = Devel::Symdump->new($mod);
+ my @methods = ();
+ foreach my $method (map { s/^\Q$mod\E:://; $_ } $dump->functions) {
+ push @methods, $method;
+
+ my $nocap = nocap( $method );
+ push @methods, $nocap if $nocap ne $method;
+ }
+ can_ok( $mod, @methods );
+}
+
+sub nocap
+{
+ my $method = shift;
+ return $method if grep( { $_ eq $method } @SPEC_METHODS );
+ $method =~ s/(?<=[a-z])([A-Z]+)/"_" . lc($1)/eg;
+ return lc($method);
+}
+
==== BEGIN SVK PATCH BLOCK ====
Version: svk 0.29 (linux)
eJxVU1Fv21QULi9IsZAQ/QHoLvNUZ8x1Yidp4ywh7Ww3adNmW1JQWYt1Y1831m5sx/c6bakzZDup
NDYkHgCJJ14QQvxKrtMhwYutc873ffece89nhKNmpxK32+WYr5Tj4VdHqvocUmvyiEV8PUa2S/2Q
r8UYzRHmlRj7l3w19uAUsSqF4SWi7XaFkXfvyfqa8K9INdcYQ+p7hG+sxUwaIsRXYrmjxB05Zl8W
VFjRD5Bnhr5P2SFyVWY1M+/Iwj5BZs7M0fUcLfO7MbRt03ExU1LicsXzLRiYMHC3aa5m8nIsVpg0
U6h9ULDdEFmss5sckEvV7qswCPCNSdE1tRGmMJc3+Xotv4qTjY2Nu/PkKFN+Nzb/Njb/OLlItLNf
D8gBNpKPfx4m9bfa5++O6n8N0o3feunmSksf3vWSrV8Oky09/UxPZkm3oWUfLbX0jZ5yySD5/o6F
iZEJ77Xs5Did69nXP7LMeyMT3zHGqpeNkm7m3+nZ46WWyfqyn/Qyn2FfLB8by37aXc4TLXvQXT59
qy3PskMG19NZZiyHqZGVDrLZT72V9oO2/DRl/2RwzZi9lf7n4Wqk3TWM1SfGSnr4QIpIKI1dTwpQ
iIF4xXERQYDQ0LVoc4QIVdVjP0RNbl8/6J2AWxCiWcRuDxSpFFEXk+0AF8FiDkMCZldCZ/hcf2Ye
66PuQBuCzvFAO+3rw1KTm96A1t7paNAf7GlA04ejl4Mz8Kw/ONG1/d61qg4RDK3JfuRiG4VAVV8i
yw/tkocRIQJAc4i1fOcY8GZqR9MALEAJ3HKFAEMPkNcue3CMQasNtlwCPJ8C1yOUpZC91eQWAGGC
K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