[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [860] trunk/LedgerSMB/DBObject.pm



Revision: 860
          http://svn.sourceforge.net/ledger-smb/?rev=860&view=rev
Author:   einhverfr
Date:     2007-03-07 18:26:39 -0800 (Wed, 07 Mar 2007)

Log Message:
-----------
Porting DBObject to use AUTOLOAD

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject.pm

Modified: trunk/LedgerSMB/DBObject.pm
===================================================================
--- trunk/LedgerSMB/DBObject.pm	2007-03-07 22:22:51 UTC (rev 859)
+++ trunk/LedgerSMB/DBObject.pm	2007-03-08 02:26:39 UTC (rev 860)
@@ -25,45 +25,33 @@
 no strict 'refs';
 use warnings;
 
-sub make_object {
-	my ($request, $name, $package_name) = @_;
-	my $self = {};
-	$self->{__dbh} = $request->{dbh};
-	$self->{__name} = $name;
-	$self->{__methods} = [];
+sub AUTOLOAD {
+	my ($ref) = shift @_;
+	my ($funcname) = shift @_;
 
 	my $query = 
-		"SELECT proname, proargnames FROM pg_proc
-		  WHERE proname ilike ?";
+		"SELECT proname, proargnames FROM pg_proc WHERE proname = ?";
 	my $sth = $self->{__dbh}->prepare($query);
-	$sth->execute("$name".'_%');
+	$sth->execute($funcname);
 	my $ref;
 
-	while ($ref = $sth->fetchrow_hashref(NAME_lc)){
-		my $m_name = $ref->{proname};
-		my $args = $ref->{proargnames};
-		my $subcode
-		if ($m_name ~= s/$name\_//){
-			push @{$self->{__methods}}, $m_name;
-			if ($args){
-				$subcode = "sub {
-					LedgerSMB::callproc($self->{proname}"
-				for $arg (@$args){
-					if ($arg =~ s/in_//){
-						$subcode .= ", \$self->{$arg}";
-					}
+	$ref = $sth->fetchrow_hashref(NAME_lc);
+	my $m_name = $ref->{proname};
+	my $args = $ref->{proargnames};
+	my @proc_args;
+
+	if ($m_name ~= s/$name\_//){
+		push @{$self->{__methods}}, $m_name;
+		if ($args){
+			for $arg (@$args){
+				if ($arg =~ s/^in_//){
+					push @proc_args, $ref->{$arg};
 				}
-				$subcode .= "); }"
-				*{$package_name . "::" . $m_name}
-					= eval $subcode;
-				
 			}
-			else {
-				$subcode = "sub {
-					LedgerSMB::callproc($self->{proname}, ".
-					"..hidden..); }"
-			}
 		}
-		*{$package_name . "::" . $m_name} = eval $subcode;
-	}	
+		else {
+			@proc_args = @_;
+		}
+	}
+	LedgerSMB::callproc($funcname, @proc_args);
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.