$self->sis->add_event("event name"); $self->sis->log_event("message"); $self->sis->uuid(); sub sis { return Company::Dept->new($dbh, $uname); }
Every time you call a method on $self->sis you're going to construct a new instance of Company::Dept, which means you might as well not bother constructing instances at all, since you'll never retrieve any instance data.
I don't fully understand what $self is in the top three statements, but here's a way to have $self->sis persist from one statement to the next:
sub sis { my ($self) = @_; # check whether the internal representation is already defined if ( !$self->{_sis} ) { # call the constructor and save the result my ($dbh, $uname) = get_constructor_args_from_somewhere(); $self->{_sis} = Company::Dept->new($dbh, $name); } return $self->{_sis}; }
In reply to Re: OO code reuse in CGI::Application
by Narveson
in thread OO code reuse in CGI::Application
by Qiang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |