summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject.pm
blob: e2441beb9692a23da49c99e1e03eff7168f4831f (plain)
  1. =head1 NAME
  2. LedgerSMB::DBObject - LedgerSMB class for building objects from db relations
  3. =head1 SYOPSIS
  4. This module creates object instances based on LedgerSMB's in-database ORM.
  5. =head1 METHODS
  6. =item find_method ($hashref, $function_name, @args)
  7. =head1 Copyright (C) 2007, The LedgerSMB core team.
  8. This file is licensed under the Gnu General Public License version 2, or at your
  9. option any later version. A copy of the license should have been included with
  10. your software.
  11. =back
  12. =cut
  13. package LedgerSMB::DBObject;
  14. use LedgerSMB;
  15. use strict;
  16. no strict 'refs';
  17. use warnings;
  18. @ISA = (LedgerSMB);
  19. sub exec_method {
  20. my ($self) = shift @_;
  21. my ($funcname) = shift @_;
  22. my $query =
  23. "SELECT proname, proargnames FROM pg_proc WHERE proname = ?";
  24. my $sth = $self->{__dbh}->prepare($query);
  25. $sth->execute($funcname);
  26. my $ref;
  27. $ref = $sth->fetchrow_hashref(NAME_lc);
  28. if (!$ref){ # no such function
  29. $self->error($locale->text("No such function: ") .$funcname;
  30. die;
  31. }
  32. my $m_name = $ref->{proname};
  33. my $args = $ref->{proargnames};
  34. my @proc_args;
  35. if ($m_name ~= s/$name\_//){
  36. push @{$self->{__methods}}, $m_name;
  37. if ($args){
  38. for $arg (@$args){
  39. if ($arg =~ s/^in_//){
  40. push @proc_args, $ref->{$arg};
  41. }
  42. }
  43. }
  44. else {
  45. @proc_args = @_;
  46. }
  47. }
  48. $self->callproc($funcname, @proc_args);
  49. }