next up previous
Next: 4.2 Permissions Up: 4 Hacking Previous: 4 Hacking

Subsections


4.1 The $S Object

Everthing in Scoop is accessed using the $S object. This object is a central "portmanteau" object that carries around lots of information about the current user, server, scoop system, etc. It is belssed into the package "Scoop", and since almost every library in the system is also part of this package, every method (subroutine) here can usually be called from $S, with the usual perl OO syntax. So, $S is a pretty important thing to know about.

What follows is some documentation on some of the more useful methods and data stored within it.


4.1.1 $S Object data

This is not an exaustive list, but this contains some of the more used variables in $S. Some of these double as methods, and they will be noted in the method section, below.

$S->{SERVER_NAME}This holds the name of the current server. Usually it will be whatever the vhost of apache was set to.
$S->{REMOTE_IP}The IP of the client machine (the user accessing this page).
$S->{APACHE}A pass-through to the mod_perl apache request object (known in the mod_perl docs as $r, usually). See perldoc Apache for more on this. Also used as $S->apache()
$S->{PARAMS}A hash reference containing all GET or POST arguments passed in this request. This should not be accessed directly, but through the $S->cgi->param() method. But here's where param() gets it's answers from.
$S->{CONFIG}All that stuff in the httpd.conf? Here's where it ends up. This is another simple pass-through to the return value of Apache dir_config(). Generally it will be ahashref with simple key/value pairs. aka. $S->CONFIG()
$S->{CGI}A pass-through to a Scoop::CGI object. This used to be a normal CGI object, until I realized that I was trading a meg of memory per httpd for about three of the methods of CGI. So I wrote a quick drop-in replacement for the bits of CGI I did use. Look at perldoc Scoop::CGI for more info. Oh yeah, you probably won't need to touch this directly too- everything useful it does through methods. aka $S->cgi()
$S->{DBH}A pass-through to a normal DBI database handle object. This is especially useful in quoting data, which is as easy as $S->{DBH}->quote($foo). aka $S->dbh aka $S->db
$S->{SESSION}This holds the user session object. Don't use this member directly. Access it through the $S->session() method.
$S->{SESSION_KEY}The unique identifier for the current user session. See perldoc Apache::Session for more on how all that works. You probably won't need this, ever.
$S->{TEMPLATE}A Scoop::Template object. See perldoc Scoop::Template for more info on this. aka $S->template
$S->{UI}This is the top-level container for all those nifty vars and blocks. It is a hashref with two parts; $S->{UI}->{VARS} and $S->{UI}->{BLOCKS}. See below for more on each.
$S->{UI}->{VARS}This holds all the things that appear in the "Vars" web interface. To get the value of var 'foo', just look in $S->{UI}->{VARS}->{foo}. Simple as that. Generally if you want something to be user- configurable, this is the best way to do it- create a new default Var, and then use that in your code.
$S->{UI}->{BLOCKS}This, like VARS, is where the Blocks are found. Same as above. If you're adding code that could use a longer chunk of configurable HTML, add a Block and use it with $S->{UI}->{BLOCKS}->{blockname}.
$S->{APR}An Apache::Request object (not to be confused with $S->{APACHE}). Eventually could be used to get at uploads. aka $S->apr


4.1.2 $S Object methods

Since pretty much every method that is in Scoop is in $S, I won't list them all here. Rather I will list some of the more general ones, and the more specific ones will be listed in the sections dedicated to their uses.

$S->_get_remote_ip()This checks whether we have a proxy in front of us, which is fairly common to mod_perl. Either way, it returns the real remote client IP.
$S->count_words($string)This just counts all of the words given in the string passed to it. Useful for checking the number of words in a post or story. Disregards all HTML.
$S->count_chars($string)This returns the number of characters in the string passed to it, disregarding HTML.
$S->urlify($string)This escapes a string, useful for providing links when some of the args in contain non-alphanumeric characters. Escapes everything except letters, numbers, underscore, period, and dash.


next up previous
Next: 4.2 Permissions Up: 4 Hacking Previous: 4 Hacking