[Rt-devel] [PATCH] AUTOLOAD cleanup
Ruslan U. Zakirov
Ruslan.Zakirov at miet.ru
Sat May 21 08:24:28 EDT 2005
Hello.
Send new patch that changes AUTOLOAD sub:
First and main change is using of `goto &$AUTOLOAD` syntax, that helps
avoid code duplication and hides AUTOLOAD sub from stack trace. I think
this also would help implement CompileAllAutoSubs method easier.
It's also one of the steps to better tests coverage.
--
Regards, Ruslan.
-------------- next part --------------
=== SearchBuilder/Record.pm
==================================================================
--- SearchBuilder/Record.pm (revision 1637)
+++ SearchBuilder/Record.pm (local)
@@ -419,16 +419,14 @@
# {{{ sub AUTOLOAD
sub AUTOLOAD {
- my $self = shift;
+ my $self = $_[0];
no strict 'refs';
- my $Attrib;
- if ( $AUTOLOAD =~ /.*::(\w+)/o ) {
- $Attrib = $1;
- }
- if ( $Attrib && $self->_Accessible( $Attrib, 'read' ) ) {
+ my ($Attrib) = ( $AUTOLOAD =~ /::(\w+)$/o );
+
+ if ( $self->_Accessible( $Attrib, 'read' ) ) {
*{$AUTOLOAD} = sub { return ( $_[0]->_Value($Attrib) ) };
- return ( $self->_Value($Attrib) );
+ goto &$AUTOLOAD;
}
elsif ( $AUTOLOAD =~ /.*::[sS]et_?(\w+)/o ) {
$Attrib = $1;
@@ -438,16 +436,12 @@
*{$AUTOLOAD} = sub {
return ( $_[0]->_Set( Field => $Attrib, Value => $_[1] ) );
};
-
- my $Value = shift @_;
- return ( $self->_Set( Field => $Attrib, Value => $Value ) );
+ goto &$AUTOLOAD;
}
elsif ( $self->_Accessible( $Attrib, 'read' ) ) {
- *{$AUTOLOAD} = sub {
- return ( 0, 'Immutable field' );
- };
- return ( 0, 'Immutable field' );
+ *{$AUTOLOAD} = sub { return ( 0, 'Immutable field' ) };
+ goto &$AUTOLOAD;
}
else {
return ( 0, 'Nonexistant field?' );
@@ -457,13 +451,12 @@
$Attrib = $1;
if ( $self->_Accessible( $Attrib, 'object' ) ) {
*{$AUTOLOAD} = sub {
- my $s = shift;
- return $s->_Object(
+ return (shift)->_Object(
Field => $Attrib,
Args => [@_],
);
};
- return $self->_Object( Field => $Attrib, Args => [@_] );
+ goto &$AUTOLOAD;
}
else {
return ( 0, 'No object mapping for field' );
@@ -478,8 +471,7 @@
$Attrib = $1;
*{$AUTOLOAD} = sub { return ( $_[0]->_Validate( $Attrib, $_[1] ) ) };
- my $Value = shift @_;
- return ( $self->_Validate( $Attrib, $Value ) );
+ goto &$AUTOLOAD;
}
# TODO: if autoload = 0 or 1 _ then a combination of lowercase and _ chars,
More information about the Rt-devel
mailing list