From e3938391654168316f393f55a688df29a9a38c48 Mon Sep 17 00:00:00 2001 From: einhverfr Date: Thu, 8 Mar 2007 02:26:39 +0000 Subject: Porting DBObject to use AUTOLOAD git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@860 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/DBObject.pm | 54 ++++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 33 deletions(-) (limited to 'LedgerSMB/DBObject.pm') diff --git a/LedgerSMB/DBObject.pm b/LedgerSMB/DBObject.pm index fed0a8e6..77869f7f 100644 --- a/LedgerSMB/DBObject.pm +++ b/LedgerSMB/DBObject.pm @@ -25,45 +25,33 @@ use strict; 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}, ". - "\@_); }" } } - *{$package_name . "::" . $m_name} = eval $subcode; - } + else { + @proc_args = @_; + } + } + LedgerSMB::callproc($funcname, @proc_args); } -- cgit v1.2.3