Okay, so how do collections work? Here's an example:
my $user = $R->user->fetch( $uid ); print "Username: ", $user->username, "\n"; $user->set( 'first_name', 'Ding' ); $user->set( 'last_name', 'Dong' ); my $rv = $user->save(); if ( ! $rv ) { $R->error->add( 513, "Cannot add user record!" ); } ... # Find all the user objects where the user's last name # begins with w my $user_list = $R->user->fetch_group( where => "last_name like 'w%'" ); foreach my $user ( @{ $user_list } ) { print "Username: ", $user->username, "\n"; print "Full Name: ", $user->full_name, "\n"; }
And so on. These are obviously really simplistic examples. But the idea is there. The variable $R is an object that acts as a container for other objects that live throughout the life of an http request -- much like the variable commonly called $r that is the first argument to any mod_perl handler.
Generally, there's a DBI database handle ($R->db), a server-wide configuration object ($R->config), the apache server rec object in perl ($R->apache), and a CGI object ($R->cgi). I've subclassed the base $R object to provide class aliasing as well. This way, I can call: $R->user which simply returns a class name (e.g., Intes::User) that can then be used to call an actual class method (e.g., $R->user->fetch( $uid ) becomes Intes::User->fetch( $uid )).
I'll try to get some basic stuff up on my website soon, depending on what Rusty winds up saying... :)
(Originally posted elsewhere)