summaryrefslogtreecommitdiff
path: root/LedgerSMB
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-03-14 18:09:59 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-03-14 18:09:59 +0000
commitc97ad04509d3f96fd9928d88eb191f4a84808f42 (patch)
treeece75efb0694d8600882b1c18b159f99e75666fa /LedgerSMB
parent43ebbcc41b5752e054eb1d7e78f1a5de5ba275af (diff)
More documentation to DBObject, changed constructor format to use named params, and consolidated conditionals in LedgerSMB::escape
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@898 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB')
-rw-r--r--LedgerSMB/DBObject.pm34
-rw-r--r--LedgerSMB/Employee.pm14
2 files changed, 22 insertions, 26 deletions
diff --git a/LedgerSMB/DBObject.pm b/LedgerSMB/DBObject.pm
index 0a79590e..4d6dabcb 100644
--- a/LedgerSMB/DBObject.pm
+++ b/LedgerSMB/DBObject.pm
@@ -8,7 +8,16 @@ This module creates object instances based on LedgerSMB's in-database ORM.
=head1 METHODS
-=item find_method ($hashref, $function_name, @args)
+=item new ($class, base => $LedgerSMB::hash)
+
+This is the base constructor for all child classes. It must be used with base
+argument because this is necessary for database connectivity and the like.
+
+Of course the base object can be any object that inherits LedgerSMB, so you can
+use any subclass of that. The per-session dbh is passed between the objects
+this way as is any information that is needed.
+
+=item exec_method ($self, procname => $function_name, args => \@args)
=item merge ($hashref, @attrs)
copies @attrs from $hashref to $self.
@@ -33,26 +42,25 @@ our $AUTOLOAD;
sub AUTOLOAD {
my ($self) = shift;
- my $type = (Scalar::Util::reftype $self) =~ m/::(.*?)$/;
- print "Type: $type\n";
- $type =~ m/::(.*?)$/;
+ my $type = Scalar::Util::blessed $self;
+ $type =~ m/::(.*?)$/;
$type = lc $1;
- $self->exec_method("$type" . "_" . $AUTOLOAD, @_);
+ print "Type: $type\n";
+ $self->exec_method(procname => "$type" . "_" . $AUTOLOAD, args => \@_);
}
sub new {
- my $self = shift @_;
- my $lsmb = shift @_;
- if (! $lsmb->isa('LedgerSMB')){
+ my $class = shift @_;
+ my %args = @_;
+ my $base = $args{base};
+ my $self = bless {}, $class;
+ if (! $base->isa('LedgerSMB')){
$self->error("Constructor called without LedgerSMB object arg");
}
- $self = {};
my $attr;
- for $attr (keys %{$lsmb}){
- $self->{$attr} = $lsmb->{$attr};
- }
- bless $self;
+ $self->merge($base);
+ $self;
}
diff --git a/LedgerSMB/Employee.pm b/LedgerSMB/Employee.pm
index 261d9578..0512cf64 100644
--- a/LedgerSMB/Employee.pm
+++ b/LedgerSMB/Employee.pm
@@ -29,22 +29,10 @@ your software.
=cut
package LedgerSMB::Employee;
-use LedgerSMB;
-use LedgerSMB::DBObject;
+use base qw(LedgerSMB::DBObject);
use strict;
our $VERSION = '1.0.0';
-our @ISA = qw(LedgerSMB::DBObject);
-
-sub AUTOLOAD {
- my $self = shift;
- my $AUTOLOAD = $LedgerSMB::Employee::AUTOLOAD;
- $AUTOLOAD =~ s/^.*:://;
- my $procname = "employee_$AUTOLOAD";
- $self->exec_method(procname => "employee_$AUTOLOAD", args => \@_);
- my @call_args;
-}
-
sub save {
my $self = shift;
my $hashref = shift @{$self->exec_method(procname => "employee_save")};