in reply to Re: Class Questions, OOP, and mod_perl -- HELP
in thread Class Questions, OOP, and mod_perl -- HELP

-- In general, things that a user can do belong in the User class, while things your application can do with a user belong somewhere else.

Yeah, thats what I'm going for. I just saw the cookie/session stuff to more of a user type thing than an application -- because the cookie/session stuff would affect the loggedIn/virgin status of the user.

I do have a bit of a procedural model in here (psuedocode below, as I'm at work and the real code is at home):
$r = apache registry; $user = new myPackage::User(\$r); $page = new myPackage::Page(\$user) $r->send_headers() $r->print( $page->getContent )
So i instantiate a new user, who contains various methods, variables, and refs to their particular get/post and session data

Then i instantiate a new page, which contains a ref to the user who requested that page. An internal subroutine decides which page to show based on the user's get/post data , checks whether the user has enough privileges to process that page, and returns the html representation.

That seems to work well for my needs -- splitting the logic behind a user and a page into separate trees.

Replies are listed 'Best First'.
Re: Re: Re: Class Questions, OOP, and mod_perl -- HELP
by perrin (Chancellor) on Apr 29, 2004 at 17:39 UTC
    I don't know anything about your application, but passing an Apache request object ($r) to your User class sets off all kinds of alarm bells. You usually want your data model classes to be totally independent of the environment they run in, e.g. you should be able to call your User class in a cron job that does some batch process on Users.
      I struggled with that.. but this user/class is just for mod_perl applications, and this seemed the easiest way to get at the specific data i needed into the user object (ie, the cookie/get/post input/session ids) for a while I had:
      $r = apache request; $session_and_form = new myPackage::session_and_form( \$r); $user = new myPackage::User(\$session); $page = new myPackage::Page(\$user)
      but it seemed more right just sending the apache ref to the user, and have the user create internal refs to the session/form info it needs on init
      im new to mod_perl, as is very evident by my questions and approach. i'm bound to be doing manny things wrong... but its working.