Jifty::ClassLoader - Loads the application classes
Jifty::ClassLoader loads all of the application's model and action
classes, generating classes on the fly for Collections of pre-existing
Returns a new ClassLoader object. Doing this installs a hook into
@INC that allows Jifty::ClassLoader to dynamically create
needed classes if they do not exist already. This works because if
use/require encounters a blessed reference in
@INC, it will
invoke the INC method with the name of the module it is searching
for on the reference.
Takes one mandatory argument,
base, which should be the the
application's or a plugin's base path; all of the classes under this will be
Jifty::ClassLoader objects are singletons per
base. If you call
and a class loader for the given base has already been initialized, this will
return a reference to that object rather than creating a new one.
The hook that is called when a module has been
cannot be found on disk. The following stub classes are
auto-generated the class loader.
Here the "Application" indicates the name of the application the class
loader is being applied to. However, this really just refers to the
argument passed to the constructor, so it could refer to a plugin class
or just about anything else.
The class loader will search for a plugin Plugin such that
Plugin::Action::Something exists. It will then create an empty class named Application::Action::Something that descends from Plugin::Action::Something.
This means that a plugin may be written to allow the application to override the default implementation used by the plugin as long as the plugin uses the application version of the class.
Plugin::Model::Something exists and is a model class, then it creates a subclass of it named
Application::Model::Something for the local application.
This allows an application to customize a model provided by a subclass (or choose not to). Plugins should be written to use the application's version.
Application::Model::Somethingis a valid model class, then it creates a subclass of Jifty::Collection whose
The class loader will search for a plugin Plugin such that Plugin::Notification::Something exists. It will then create an empty class named Application::Notification::Something that descends from Plugin::Notification::Something.
This allows an application to customize the email notification sent out by a plugin as long as the plugin defers to the application version of the class.
A helper method; takes CODE as a string and returns an open filehandle containing that CODE.
Loads all of the application's Actions and Models. It additionally
require's all Collections and Create/Update actions for each Model
base class -- which will auto-create them using the above code if they
do not exist on disk.
Jifty supports model classes that aren't files on disk but instead records in your database. It's a little bit mind bending, but basically, you can build an application entirely out of the database without ever writing a line of code(*).
* As of early 2007, this forward looking statement is mostly a lie. But we're working on it.
This method finds all database-backed models and instantiates jifty classes for them it returns a list of class names of the models it created.
$appname::View, the view class for the application.
Accessor to the list of models this application has loaded.
In scalar context, returns a mutable array reference; in list context, return the content of the array.
ClassLoaders stringify as
Jifty::ClassLoader(base class name)
When the ClassLoader gets garbage-collected, its entry in @INC needs to be removed.
Returns true if the package was autogenerated by a classloader.
If you require more functionality than is provided by the classes created by ClassLoader (which you'll almost certainly need to do if you want an application that does more than display a pretty Pony) then you should create a class with the appropriate name and add your extra logic to it.
For example you will almost certainly want to write your own dispatcher, so something like:
package MyApp::Dispatcher; use Jifty::Dispatcher -base;
If you want to add some application specific behaviour to a model's collection class, say for the User model, create UserCollection.pm in your applications Model directory.
package MyApp::Model::UserCollection; use base 'MyApp::Collection';
Jifty and just about every other class that this provides an empty override for.
Jifty is Copyright 2005-2010 Best Practical Solutions, LLC. Jifty is distributed under the same terms as Perl itself.