diff options
author | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-03-08 02:26:39 +0000 |
---|---|---|
committer | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-03-08 02:26:39 +0000 |
commit | e3938391654168316f393f55a688df29a9a38c48 (patch) | |
tree | 42bef94c0dcf1c0f19d7db8ea6439d2f78f2417c /LedgerSMB/DBObject.pm | |
parent | f02f244549e2806ca03f2899d1193055ad19d544 (diff) |
Porting DBObject to use AUTOLOAD
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@860 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/DBObject.pm')
-rw-r--r-- | LedgerSMB/DBObject.pm | 54 |
1 files changed, 21 insertions, 33 deletions
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); } |