dsheroh,

Many thanks for your hand-holding. I am almost there, but consider the following variation on your suggestion (my relevant edits, the ones that don't work for me, marked with ## desired ##)

#!/usr/local/bin/perl -w use strict; use DBI qw(:sql_types); use Obj; use constant ( PI => 3.1425 ); { my %CACHE = (); sub cache { my ($self, $cid, $val) = @_; if (defined $val) { %CACHE = (); # empty the cache $CACHE{$cid} = $val; # stuff cache with new val return $val; } else { return $CACHE{$cid} if exists $CACHE{$cid}; } } } my $dbh = DBI->connect( "dbi:SQLite:dbname=db.sqlite","","", {RaiseError => 1, AutoCommit => 0} ); my $obj = Obj->new(dbh => $dbh, uid => 1, cid => 1); print "\$obj->foo called Foo::foo\n"; ##################################### package Obj; use strict; use Foo; sub new { my ($class, %args) = @_; my $self = bless( {dbh => $args{dbh}, uid => $args{uid}, cid => $args{cid},}, $class ); $self->{foo} = Foo->new; return $self; } sub foo { my $self = shift; print "In Obj::foo and about to pass the buck.\n"; return $self->{foo}->foo(@_); } sub dbh { my $self = shift; return $self->{dbh}; } sub cid { my $self = shift; return $self->{cid}; } sub uid { my $self = shift; return $self->{uid}; } 1; ##################################### package Foo; use strict; sub new { return bless { }; } sub foo { print "In Foo::foo, where the work gets done.\n"; ## desired: be able to call Obj::instance_methods like so ## print "Cell id is: " . $self->cid() . "\n"; ## ## desired: be able to access Obj::class_methods, ## class vars and class constants like so ## my $dbh = $self->dbh; my $sth = $dbh->prepare("SELECT * FROM cells WHERE cid = ?"); $sth->execute; my @res = $sth->fetchrow_array; $self->cache($self->cid, \@res); # class method print "Have a pi: " . Obj::PI . "\n"; # class constant ## return 1; } 1;
--

when small people start casting long shadows, it is time to go to bed

In reply to Re^4: Designing an OO program with multiple inherited classes by punkish
in thread Designing an OO program with multiple inherited classes by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.