Zinc::Director

From Deep Thought

Jump to: navigation, search

Zinc::Director

NAME

Zinc::Director

DESCRIPTION

This module directs the "show". It is the main processor that dictates what we are going to do for the application. Show something via a VIEW? Act on something via the ACTIONS module?

SYNOPSIS

 use CGI::Carp qw(fatalsToBrowser);
 use Zinc::Director;

 # Our Custom Zinc Modifications
 #
 use lib './zincmods/';
 use MyView;
 use MyAct;

 # Activate The Zinc Director
 #
 my $Director    = new Zinc::Director(
                            DBName      => 'mydb',
                            DBUser      => 'myuser',
                            ViewModule  => 'MyView',
                            ActModule   => 'MyAct'
                            );

 print $Director->{WebIO}->header;
 $Director->Act;
 $Director->Display('wireframe');

 exit;

REQUIRES

 CGI
 Zinc::Act
 Zinc::View
    HTML::TemplateZ
 Zinc::Memory
    Postgres::Handler

METHODS

new()

Create a new Zinc::Director object.

An interesting and important feature to take note of is the special processing of the CGI variable named 'cmd'. Whenever the Director sees this special CGI variable name it takes the value of the cmd setting and splits it apart on the slashes to set the Command, Context, and Directive properties for the Director.

For example, call a Director enabled application with a URL like this: myapp.pl?cmd=a/b/c And your properties are set to Command='a', Context='b', Directive='c'.

Properties

 CodeEnd        => Pair of chars that end a template processing tag (_Z)
 CodeStart      => Pair of chars that start a template processing tag (Z_)
 Command        => Active command for the application (show)
 Context        => Current command context (intro)
 Directive      => What to do with the command and context
 DBName         => Name of the database for the Memory object
 DBPass         => Password for connection to the database
 DBUser         => Username for connection to the database
 GateKeeper     => Instatiated GateKeeper Object (optional)
 TemplateName   => Name of the template being used (plainjane)
 ActModule      => Name of Action processing object
 ViewModule     => Name of View display object
 MemoryModule   => Name of Data store object

Properties (read only)

 Act            => The instantiated act object
 View           => The instantiated view object
 Module         => The instantiated memory object
 WebIO          => Web IO (CGI class) object

Act()

Handle any actions that need to be, well, handled. We determine the action by looking at the Command property attached to the Director object we are told to act on.

The commands that we know about currently include:

act

Whatever you put into the Context property of the Director object is what we are going to do by looking for a method with the same name as the Context property.

Browser()

Return a CGI variable from the Director->{WebIO} object.

 Example:
 $self->DoSomethingCool($self->Browser('formentry'));

Display()

Display a Zinc Template.

Calls the active View object that is attached to the Director, the default being a Zinc::View object. Sometimes this is overridden with a MyView object that is based on the Zinc::View object.

Parameters (required)

 $_[0] = the name of the file to be displayed from the template directory

Reset()

Resets the Command, Context, and Directive properties to the defaults setup when this Director was invoked.

SetMessage()

Sets the View Object Message property for later regurgitation via <%SELF(Message)%>

NOTES

 None.

EXAMPLES

Perform A Login

 use Zinc::Director;
 use lib './zincmods/';
 use MyAct;
 my $Director    = new Zinc::Director(
                            DBName      => 'mydb',
                            DBUser      => 'myuser',
                            ActModule   => 'MyAct'
                            );


  # normally these two properties are set in a more exciting fashion
  # for example using the ?cmd= directive on a URL string which is
  # typically masked with mod_rewrite.
  #
 $Director->{Command} = 'act';          # force our command to 'act'
 $Director->{Context} = 'login';        # and force the context to login

 print $Director->{WebIO}->header;      # send the content-type header
 $Director->Act;                        # perform our action
 $Director->Display('wireframe');       # show the results

 exit;

AUTHOR

 Cyber Sprocket Labs, Advanced Internet Technology Consultants
 Contact info@cybersprocket.com for more info.

ABOUT CSL

 Cyber Sprocket Labs (CSL) is and advanced internet technology
 consulting firm based in Charleston South Carolina.   We provide custom
 software, database, and consulting services for small to mid-sized
 businesses.

 For more information, or to schedule a consult, visit our website at
 www.cybersprocket.com

CONTRIBUTIONS

 Like the script and want to contribute?
 You can send payments via credit card or bank transfer using
 PayPal and sending money to our paypal@cybersprocket.com PayPal address.

COPYRIGHT

 This script is covered by the GNU GENERAL PUBLIC LICENSE.
 View the license at http://www.gnu.org/copyleft/gpl.html
 (c) 2008, Cyber Sprocket Labs

REVISION HISTORY

 v0.1 - May 2007
    First go.

Personal tools
Cyber Sprocket Labs
Cyber Sprocket Tech