| 1 | 113 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 2 | 113 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | package Jifty::ClassLoader; | ||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 113 | our %AUTOGENERATED; | |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 113 | ▶ | use overload '""' => \&stringify, fallback => 1; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | Jifty::ClassLoader - Loads the application classes | ||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | C<Jifty::ClassLoader> loads all of the application's model and action | ||||||||||||||||||||||||||||||||||
| 17 | classes, generating classes on the fly for Collections of pre-existing | ||||||||||||||||||||||||||||||||||
| 18 | models. | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | =head2 new | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | Returns a new ClassLoader object. Doing this installs a hook into | ||||||||||||||||||||||||||||||||||
| 23 | C<@INC> that allows L<Jifty::ClassLoader> to dynamically create | ||||||||||||||||||||||||||||||||||
| 24 | needed classes if they do not exist already. This works because if | ||||||||||||||||||||||||||||||||||
| 25 | use/require encounters a blessed reference in C<@INC>, it will | ||||||||||||||||||||||||||||||||||
| 26 | invoke the INC method with the name of the module it is searching | ||||||||||||||||||||||||||||||||||
| 27 | for on the reference. | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | Takes one mandatory argument, C<base>, which should be the the | ||||||||||||||||||||||||||||||||||
| 30 | application's or a plugin's base path; all of the classes under this will be | ||||||||||||||||||||||||||||||||||
| 31 | automatically loaded. | ||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | L<Jifty::ClassLoader> objects are singletons per C<base>. If you call C<new> | ||||||||||||||||||||||||||||||||||
| 34 | and a class loader for the given base has already been initialized, this will | ||||||||||||||||||||||||||||||||||
| 35 | return a reference to that object rather than creating a new one. | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 40 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 41 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | # Check to make sure this classloader hasn't been built yet and stop if so | ||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my @exist = grep {ref $_ eq $class and $_->{base} eq $args{base}} @INC; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $_ eq $class && $_->{'base'} eq $args{'base'}
MC/DC0%0/2
ref $_ eq $class && $_->{'base'} eq $args{'base'}
ref $_ eq $class
$_->{'base'} eq $args{'base'}
Truth table0%0/3
A && B
A= ref $_ eq $classB= $_->{'base'} eq $args{'base'}
| |||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return $exist[0] if @exist; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | # It's a new one, build it | ||||||||||||||||||||||||||||||||||
| 48 | 0 | my $self = bless {%args}, $class; | |||||||||||||||||||||||||||||||||
| 49 | 0 | push @INC, $self; | |||||||||||||||||||||||||||||||||
| 50 | 0 | return $self; | |||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | =head2 INC | ||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | The hook that is called when a module has been C<require>'d that | ||||||||||||||||||||||||||||||||||
| 56 | cannot be found on disk. The following stub classes are | ||||||||||||||||||||||||||||||||||
| 57 | auto-generated the class loader. | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | Here the "I<Application>" indicates the name of the application the class | ||||||||||||||||||||||||||||||||||
| 60 | loader is being applied to. However, this really just refers to the C<base> | ||||||||||||||||||||||||||||||||||
| 61 | argument passed to the constructor, so it could refer to a plugin class | ||||||||||||||||||||||||||||||||||
| 62 | or just about anything else. | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | =over | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | =item I<Application> | ||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | An empty application base class is created that doesn't provide any | ||||||||||||||||||||||||||||||||||
| 69 | methods or inherit from anything. | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | =item I<Application>::Action | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | An empty mixin class for all actions in your application. Should | ||||||||||||||||||||||||||||||||||
| 74 | B<not> inherit from L<Jifty::Action>. | ||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | =item I<Application>::Action::I<[Verb]>I<[Something]> | ||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | If I<Application>::Model::I<Something> is a valid model class and I<Verb> is one of "Create", "Search", "Update", "Execute", or "Delete", then it creates a subclass of I<Application>::Action::Record::I<Verb> Models can control which actions are generated by overriding L<Jifty::Record/autogenerate_action>. See also L<Jifty::Record/is_private> and L<Jifty::Record/is_protected>. | ||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | =item I<Application>::Action::I<Something> | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | The class loader will search for a plugin I<Plugin> such that C<I<Plugin>::Action::I<Something>> exists. It will then create an empty class named I<Application>::Action::I<Something> that descends from I<Plugin>::Action::I<Something>. | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 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. | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | =item I<Application>::Action::Record::I<Something> | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | An empty class that descends from the matching Jifty class, Jifty::Action::Record::I<Something>. This is generally used to build application-specific descendants of L<Jifty::Action::Record::Create>, L<Jifty::Action::Record::Execute>, L<Jifty::Action::Record::Search>, L<Jifty::Action::Record::Update>, or L<Jifty::Action::Record::Delete>. | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | =item I<Application>::Bootstrap | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | An empty class that descends from L<Jifty::Bootstrap>. | ||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | =item I<Application>::Collection | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | An empty class that descends from L<Jifty::Collection> is created. | ||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | =item I<Application>::CurrentUser | ||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||
| 100 | An empty class that descends from L<Jifty::CurrentUser>. | ||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | =item I<Application>::Dispatcher | ||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | An empty class that descends from L<Jifty::Dispatcher>. | ||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | =item I<Application>::Handle | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | An empty class that descends from L<Jifty::Handle> is created. | ||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | =item I<Application>::Model::I<Something> | ||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | If C<I<Plugin>::Model::I<Something>> exists and is a model class, then it creates a subclass of it named C<I<Application>::Model::I<Something>> for the local application. | ||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||
| 114 | 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. | ||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||
| 116 | =item I<Application>::Model::I<Something>Collection | ||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | If C<I<Application>::Model::I<Something>> is a valid model class, then | ||||||||||||||||||||||||||||||||||
| 119 | it creates a subclass of L<Jifty::Collection> whose C<record_class> is | ||||||||||||||||||||||||||||||||||
| 120 | C<I<Application>::Model::I<Something>>. | ||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | =item I<Application>::Notification | ||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||
| 124 | An empty class that descends from L<Jifty::Notification>. | ||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | =item I<Application>::Notification::I<Something> | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | The class loader will search for a plugin I<Plugin> such that I<Plugin>::Notification::I<Something> exists. It will then create an empty class named I<Application>::Notification::I<Something> that descends from I<Plugin>::Notification::I<Something>. | ||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||
| 130 | 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. | ||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | =item I<Application>::Record | ||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||
| 134 | An empty class that descends from L<Jifty::Record> is created. | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | =item I<Application>::Upgrade | ||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | An empty class that descends from L<Jifty::Upgrade>. | ||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | =item I<Application>::View | ||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | An empty class that descends from L<Jifty::View::Declare>. | ||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | =back | ||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | # This subroutine's name is fully qualified, as perl will ignore a 'sub INC' | ||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub Jifty::ClassLoader::INC { | ||||||||||||||||||||||||||||||||
|
Subroutine
INC: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 150 | 0 | my ( $self, $module ) = @_; | |||||||||||||||||||||||||||||||||
| 151 | 0 | my $base = $self->{base}; | |||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | return undef unless ( $module and $base ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$module and $base
MC/DC0%0/2
$module and $base
$module
$base
Truth table0%0/3
A and B
A= $moduleB= $base
| |||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||
| 154 | # Canonicalize $module to :: style rather than / and .pm style; | ||||||||||||||||||||||||||||||||||
| 155 | 0 | $module =~ s/.pm$//; | |||||||||||||||||||||||||||||||||
| 156 | 0 | $module =~ s{/}{::}g; | |||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||
| 158 | # The quick check. We only want to handle things for our app | ||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | return undef unless $module =~ /^$base/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | # If the module is the same as the base, build the application class | ||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if ( $module =~ /^(?:$base)$/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||
| 163 | 0 | return $self->return_class( "package " . $base . ";\n"); | |||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||
| 166 | # Handle most of the standard App::Class ISA Jifty::Class | ||||||||||||||||||||||||||||||||||
| 167 | elsif ( $module =~ /^(?:$base)::(Record|Collection|Notification| | ||||||||||||||||||||||||||||||||||
| 168 | Dispatcher|Bootstrap|Upgrade|CurrentUser| | ||||||||||||||||||||||||||||||||||
| 169 | Handle| | ||||||||||||||||||||||||||||||||||
| 170 | Action::Record::\w+)$/x ) { | ||||||||||||||||||||||||||||||||||
| 171 | 0 | $AUTOGENERATED{$module} = 1; | |||||||||||||||||||||||||||||||||
| 172 | 0 | return $self->return_class( | |||||||||||||||||||||||||||||||||
| 173 | "package $module;\n" | ||||||||||||||||||||||||||||||||||
| 174 | . "use base qw/Jifty::$1/; \n" | ||||||||||||||||||||||||||||||||||
| 175 | ); | ||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||
| 178 | # Autogenerate empty Action mixin | ||||||||||||||||||||||||||||||||||
| 179 | elsif ( $module =~ /^(?:$base)::Action$/) { | ||||||||||||||||||||||||||||||||||
| 180 | 0 | $AUTOGENERATED{$module} = 1; | |||||||||||||||||||||||||||||||||
| 181 | 0 | return $self->return_class( | |||||||||||||||||||||||||||||||||
| 182 | "package $module;\n" | ||||||||||||||||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||
| 186 | # Autogenerate an empty View if none is defined | ||||||||||||||||||||||||||||||||||
| 187 | elsif ( $module =~ /^(?:$base)::View$/ ) { | ||||||||||||||||||||||||||||||||||
| 188 | 0 | $AUTOGENERATED{$module} = 1; | |||||||||||||||||||||||||||||||||
| 189 | 0 | return $self->return_class( | |||||||||||||||||||||||||||||||||
| 190 | "package $module;\n" | ||||||||||||||||||||||||||||||||||
| 191 | . "use Jifty::View::Declare -base;\n" | ||||||||||||||||||||||||||||||||||
| 192 | ); | ||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | # Autogenerate the Collection class for a Model | ||||||||||||||||||||||||||||||||||
| 196 | elsif ( $module =~ /^(?:$base)::Model::([^\.]+)Collection$/ ) { | ||||||||||||||||||||||||||||||||||
| 197 | 0 | $AUTOGENERATED{$module} = 1; | |||||||||||||||||||||||||||||||||
| 198 | 0 | return $self->return_class( | |||||||||||||||||||||||||||||||||
| 199 | "package $module;\n" | ||||||||||||||||||||||||||||||||||
| 200 | 0 | . "use base qw/@{[$base]}::Collection/;\n" | |||||||||||||||||||||||||||||||||
| 201 | 0 | . "sub record_class { '@{[$base]}::Model::$1' }\n" | |||||||||||||||||||||||||||||||||
| 202 | ); | ||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||
| 205 | # Autogenerate the record actions for a model | ||||||||||||||||||||||||||||||||||
| 206 | elsif ( $module =~ /^(?:$base)::Action:: | ||||||||||||||||||||||||||||||||||
| 207 | (Create|Update|Delete|Search|Execute)([^\.]+)$/x ) { | ||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||
| 209 | 0 | my $action = $1; | |||||||||||||||||||||||||||||||||
| 210 | 0 | my $model = $2; | |||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||
| 212 | # Determine the model class and load it | ||||||||||||||||||||||||||||||||||
| 213 | 0 | my $modelclass = $base . "::Model::" . $model; | |||||||||||||||||||||||||||||||||
| 214 | 0 | Jifty::Util->_require( module => $modelclass, quiet => 1); | |||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||
| 216 | # Don't generate the action unless it really is a model | ||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if ( eval { $modelclass->isa('Jifty::Record') } ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if ($modelclass->autogenerate_action($action)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||
| 220 | # Skip autogenerated models; that is, those that are overridden | ||||||||||||||||||||||||||||||||||
| 221 | # by plugins, the special case below should take care of it | ||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if (!$self->autogenerated($modelclass)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 223 | 0 | $AUTOGENERATED{$module} = 1; | |||||||||||||||||||||||||||||||||
| 224 | 0 | return $self->return_class( | |||||||||||||||||||||||||||||||||
| 225 | "package $module;\n" | ||||||||||||||||||||||||||||||||||
| 226 | . "use base qw/$base\::Action::Record::$action/;\n" | ||||||||||||||||||||||||||||||||||
| 227 | . "sub record_class { '$modelclass' };\n" | ||||||||||||||||||||||||||||||||||
| 228 | ); | ||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||
| 235 | # This is a little hard to grok, so pay attention. This next if checks to | ||||||||||||||||||||||||||||||||||
| 236 | # see if the requested class belongs to an application (i.e., this class | ||||||||||||||||||||||||||||||||||
| 237 | # loader does not belong to a plugin). If so, it will attempt to create an | ||||||||||||||||||||||||||||||||||
| 238 | # application override of a plugin class, if the plugin provides the same | ||||||||||||||||||||||||||||||||||
| 239 | # type of notification or action. | ||||||||||||||||||||||||||||||||||
| 240 | # | ||||||||||||||||||||||||||||||||||
| 241 | # This allows the application to customize what happens on a plugin action | ||||||||||||||||||||||||||||||||||
| 242 | # or model or customize the email notification sent by a plugin. | ||||||||||||||||||||||||||||||||||
| 243 | # | ||||||||||||||||||||||||||||||||||
| 244 | # However, this depends on the plugin being well-behaved and always using | ||||||||||||||||||||||||||||||||||
| 245 | # the application version of actions, models, and notifications rather than | ||||||||||||||||||||||||||||||||||
| 246 | # trying to use the plugin class directly. | ||||||||||||||||||||||||||||||||||
| 247 | # | ||||||||||||||||||||||||||||||||||
| 248 | # Of course, if the class loader finds such a case, then the application | ||||||||||||||||||||||||||||||||||
| 249 | # has not chosen to override it and we're generating the empty stub to take | ||||||||||||||||||||||||||||||||||
| 250 | # it's place. | ||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||
| 252 | # N.B. This is if and not elsif on purpose. If the class name requested is | ||||||||||||||||||||||||||||||||||
| 253 | # App::Action::(Create|Update|Search|Delete|Execute)Thing, but there is no such | ||||||||||||||||||||||||||||||||||
| 254 | # model as App::Model::Thing, we may be trying to create a sub-class of | ||||||||||||||||||||||||||||||||||
| 255 | # Plugin::Action::(Create|Update|Search|Delete|Execute)Thing for | ||||||||||||||||||||||||||||||||||
| 256 | # Plugin::Model::Thing instead. | ||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||
| 258 | # Requesting an application override of a plugin action or notification? | ||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if ( $module =~ /^(?:$base)::(Action|Model|Notification)::(.*)$/x and not grep {$_ eq $base} map {ref} Jifty->plugins ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$module =~ /^(?:$base)::(Action|Model|Notification)::(.*)$/x and not grep({$_ eq $base;} map({ref $_;} "Jifty"->plugins))
MC/DC0%0/2
$module =~ /^(?:$base)::(Action|Model|Notification)::(.*)$/x and not grep({$_ eq $base;} map({ref $_;} "Jifty"->plugins))
$module =~ /^(?:$base)::(Action|Model|Notification)::(.*)$/x
not grep({$_ eq $base;} map({ref $_;} "Jifty"->plugins))
Truth table0%0/3
A and not(B)
A= $module =~ /^(?:$base)::(Action|Model|Notification)::(.*)$/xB= not grep({$_ eq $base;} map({ref $_;} "Jifty"->plugins))
| |||||||||||||||||||||||||||||||||||
| 260 | 0 | my $type = $1; | |||||||||||||||||||||||||||||||||
| 261 | 0 | my $item = $2; | |||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||
| 263 | # Find a plugin with a matching action or notification | ||||||||||||||||||||||||||||||||||
| 264 | 0 | foreach my $plugin (map {ref} Jifty->plugins) { | |||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | next if ($plugin eq $base); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 266 | 0 | my $class = $plugin."::".$type."::".$item; | |||||||||||||||||||||||||||||||||
| 267 | # Found it! | ||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if (Jifty::Util->try_to_require($class) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||
| 270 | # Models need to load their other stuff, but to prevent deep | ||||||||||||||||||||||||||||||||||
| 271 | # recursion, this must happen after the class is compiled. | ||||||||||||||||||||||||||||||||||
| 272 | 0 | my $module_suffix = ''; | |||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | $module_suffix = "Jifty->class_loader" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 274 | . "->_require_model_related_classes(" | ||||||||||||||||||||||||||||||||||
| 275 | . "'$module');\n" | ||||||||||||||||||||||||||||||||||
| 276 | if $type eq 'Model'; | ||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||
| 278 | # Generate the empty stub | ||||||||||||||||||||||||||||||||||
| 279 | 0 | $AUTOGENERATED{$module} = 1; | |||||||||||||||||||||||||||||||||
| 280 | 0 | return $self->return_class( | |||||||||||||||||||||||||||||||||
| 281 | "package $module;\n" | ||||||||||||||||||||||||||||||||||
| 282 | . "use base qw/$class/;\n" | ||||||||||||||||||||||||||||||||||
| 283 | . $module_suffix | ||||||||||||||||||||||||||||||||||
| 284 | ); | ||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||
| 289 | # Didn't find a match | ||||||||||||||||||||||||||||||||||
| 290 | 0 | return undef; | |||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||
| 293 | =head2 return_class CODE | ||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||
| 295 | A helper method; takes CODE as a string and returns an open filehandle | ||||||||||||||||||||||||||||||||||
| 296 | containing that CODE. | ||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||
| 298 | =cut | ||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | sub return_class { | ||||||||||||||||||||||||||||||||
|
Subroutine
return_class: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 301 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 302 | 0 | my $content = shift; | |||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||
| 304 | # ALWAYS use warnings; use strict!!! | ||||||||||||||||||||||||||||||||||
| 305 | 0 | $content = "use warnings; use strict; ". $content . "\n1;"; | |||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||
| 307 | # Magically turn the text into a file handle | ||||||||||||||||||||||||||||||||||
| 308 | 0 | open my $fh, '<', \$content; | |||||||||||||||||||||||||||||||||
| 309 | 0 | return $fh; | |||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||
| 312 | =head2 require | ||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||
| 314 | Loads all of the application's Actions and Models. It additionally | ||||||||||||||||||||||||||||||||||
| 315 | C<require>'s all Collections and Create/Update actions for each Model | ||||||||||||||||||||||||||||||||||
| 316 | base class -- which will auto-create them using the above code if they | ||||||||||||||||||||||||||||||||||
| 317 | do not exist on disk. | ||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||
| 319 | =cut | ||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | sub require { | ||||||||||||||||||||||||||||||||
|
Subroutine
require: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 322 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 323 | 0 | my $base = $self->{base}; | |||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||
| 325 | # XXX It would be nice to have a comment here or somewhere in here | ||||||||||||||||||||||||||||||||||
| 326 | # indicating when it's possible for a class loader to be missing it's base. | ||||||||||||||||||||||||||||||||||
| 327 | # This is a consistent check in the class loader, but I don't know of an | ||||||||||||||||||||||||||||||||||
| 328 | # example where this would be the case. -- Sterling | ||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||
| 330 | # if we don't even have an application class, this trick will not work | ||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | return unless ($base); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||
| 333 | # Always require the base and the base current user first | ||||||||||||||||||||||||||||||||||
| 334 | 0 | Jifty::Util->require($base); | |||||||||||||||||||||||||||||||||
| 335 | 0 | Jifty::Util->require($base."::CurrentUser"); | |||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||
| 337 | # Use Module::Pluggable to help locate our models, actions, and | ||||||||||||||||||||||||||||||||||
| 338 | # notifications | ||||||||||||||||||||||||||||||||||
| 339 | Jifty::Module::Pluggable->import( | ||||||||||||||||||||||||||||||||||
| 340 | # $base goes last so we pull in the view class AFTER the model classes | ||||||||||||||||||||||||||||||||||
| 341 | 0 | search_path => [map { $base . "::" . $_ } ('Model', 'Action', 'Notification')], | |||||||||||||||||||||||||||||||||
| 342 | require => 0, | ||||||||||||||||||||||||||||||||||
| 343 | except => qr/\.#/, | ||||||||||||||||||||||||||||||||||
| 344 | inner => 0 | ||||||||||||||||||||||||||||||||||
| 345 | ); | ||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||
| 347 | # Construct the list of models for the application for later reference | ||||||||||||||||||||||||||||||||||
| 348 | 0 | my %models; | |||||||||||||||||||||||||||||||||
| 349 | 0 | for my $p ($self->plugins) { | |||||||||||||||||||||||||||||||||
| 350 | 0 | Jifty::Util->require($p); | |||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | $models{$p} = 1 if $p =~ m/^($base)::Model::(.*)$/ and not $p =~ m/Collection(?:$||\:\:)/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p =~ /^($base)::Model::(.*)$/ and not $p =~ /Collection(?:$||\:\:)/
MC/DC0%0/2
$p =~ /^($base)::Model::(.*)$/ and not $p =~ /Collection(?:$||\:\:)/
$p =~ /^($base)::Model::(.*)$/
not $p =~ /Collection(?:$||\:\:)/
Truth table0%0/3
A and not(B)
A= $p =~ /^($base)::Model::(.*)$/B= not $p =~ /Collection(?:$||\:\:)/
| |||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||
| 353 | 0 | $self->models(sort keys %models); | |||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||
| 355 | # Load all those models and model-related actions, and notifications | ||||||||||||||||||||||||||||||||||
| 356 | 0 | for my $full ($self->models) { | |||||||||||||||||||||||||||||||||
| 357 | 0 | $self->_require_model_related_classes($full); | |||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||
| 361 | # This class helps Jifty::ClassLoader::require() load each model, the model's | ||||||||||||||||||||||||||||||||||
| 362 | # collection and the model's create, update, delete, and search actions. | ||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | sub _require_model_related_classes { | ||||||||||||||||||||||||||||||||
|
Subroutine
_require_model_related_classes: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 364 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 365 | 0 | my $full = shift; | |||||||||||||||||||||||||||||||||
| 366 | 0 | my $base = $self->{base}; | |||||||||||||||||||||||||||||||||
| 367 | 0 | my($short) = $full =~ /::Model::(\w*)/; | |||||||||||||||||||||||||||||||||
| 368 | 0 | Jifty::Util->require($full . "Collection"); | |||||||||||||||||||||||||||||||||
| 369 | Jifty::Util->require($base . "::Action::" . $_ . $short) | ||||||||||||||||||||||||||||||||||
| 370 | 0 | for grep {$full->autogenerate_action($_)} qw/Create Update Delete Search Execute/; | |||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||
| 374 | =head2 require_classes_from_database | ||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||
| 376 | Jifty supports model classes that aren't files on disk but instead records | ||||||||||||||||||||||||||||||||||
| 377 | in your database. It's a little bit mind bending, but basically, you can | ||||||||||||||||||||||||||||||||||
| 378 | build an application entirely out of the database without ever writing a | ||||||||||||||||||||||||||||||||||
| 379 | line of code(*). | ||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||
| 381 | * As of early 2007, this forward looking statement is mostly a lie. But we're | ||||||||||||||||||||||||||||||||||
| 382 | working on it. | ||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||
| 384 | This method finds all database-backed models and instantiates jifty classes for | ||||||||||||||||||||||||||||||||||
| 385 | them it returns a list of class names of the models it created. | ||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||
| 387 | =cut | ||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||
| 389 | # XXX TODO FIXME Holy crap! This is in the trunk! See the virtual-models branch | ||||||||||||||||||||||||||||||||||
| 390 | # of Jifty if you really want to see this in action (unless it's finally been | ||||||||||||||||||||||||||||||||||
| 391 | # merged intot he trunk), which isn't the case as of August 13, 2007. | ||||||||||||||||||||||||||||||||||
| 392 | # -- Sterling | ||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | sub require_classes_from_database { | ||||||||||||||||||||||||||||||||
|
Subroutine
require_classes_from_database: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 394 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 395 | 0 | my @instantiated; | |||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||
| 397 | 0 | require Jifty::Model::ModelClassCollection; | |||||||||||||||||||||||||||||||||
| 398 | 0 | require Jifty::Model::ModelClass; | |||||||||||||||||||||||||||||||||
| 399 | 0 | my $models = Jifty::Model::ModelClassCollection->new(current_user => Jifty->app_class('CurrentUser')->superuser); | |||||||||||||||||||||||||||||||||
| 400 | 0 | $models->unlimit(); | |||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | while (my $model = $models->next) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 402 | 0 | $model->instantiate(); | |||||||||||||||||||||||||||||||||
| 403 | 0 | $self->_require_model_related_classes($model->qualified_class); | |||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||
| 407 | =head2 require_views | ||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||
| 409 | Load up C<$appname::View>, the view class for the application. | ||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||
| 411 | =cut | ||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | sub require_views { | ||||||||||||||||||||||||||||||||
|
Subroutine
require_views: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 414 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 415 | 0 | my $base = $self->{base}; | |||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||
| 417 | # if we don't even have an application class, this trick will not work | ||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | return unless ($base); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 419 | 0 | Jifty::Util->require($base."::View"); | |||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||
| 422 | =head2 models | ||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||
| 424 | Accessor to the list of models this application has loaded. | ||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||
| 426 | In scalar context, returns a mutable array reference; in list context, | ||||||||||||||||||||||||||||||||||
| 427 | return the content of the array. | ||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||
| 429 | =cut | ||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | sub models { | ||||||||||||||||||||||||||||||||
|
Subroutine
models: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 432 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||
| 434 | # If we have args, update the list of models | ||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | $self->{models} = ref($_[0]) ? $_[0] : \@_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||
| 439 | # DWIM: return an array if they want a list, return an arrayref otherwise | ||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | wantarray ? @{ $self->{models} ||= [] } : $self->{models}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{"models"} ||= []
MC/DC0%0/1
$self->{"models"} ||= []
$self->{"models"}
Truth table0%0/2
A
A= $self->{"models"}
| |||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||
| 443 | =head2 stringify | ||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||
| 445 | ClassLoaders stringify as C<Jifty::ClassLoader(I<base class name>)> | ||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||
| 447 | =cut | ||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 450 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 451 | 0 | return "Jifty::ClassLoader(@{[$self->{base}]})"; | |||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||
| 454 | =head2 DESTROY | ||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||
| 456 | When the ClassLoader gets garbage-collected, its entry in @INC needs | ||||||||||||||||||||||||||||||||||
| 457 | to be removed. | ||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||
| 459 | =cut | ||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||
| 461 | # The entries in @INC end up having SvTYPE == SVt_RV, but SvRV(sv) == | ||||||||||||||||||||||||||||||||||
| 462 | # 0x0 and !SvROK(sv) (!?) This may be something that perl should cope | ||||||||||||||||||||||||||||||||||
| 463 | # with more cleanly. | ||||||||||||||||||||||||||||||||||
| 464 | # | ||||||||||||||||||||||||||||||||||
| 465 | # We call this explictly in an END block in Jifty.pm, because | ||||||||||||||||||||||||||||||||||
| 466 | # otherwise the DESTROY block gets called *after* there's already a | ||||||||||||||||||||||||||||||||||
| 467 | # bogus entry in @INC | ||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||
| 469 | # This bug manifests itself as warnings that look like this: | ||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||
| 471 | # Use of uninitialized value in require at /tmp/7730 line 9 during global destruction. | ||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 474 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | @INC = grep {defined $_ and not (ref $_ and Scalar::Util::refaddr($_) ne Scalar::Util::refaddr($self))} @INC; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
defined $_ && !(ref $_ && builtin::refaddr($_) ne builtin::refaddr($self))
ref $_ && builtin::refaddr($_) ne builtin::refaddr($self)
MC/DC0%0/3
defined $_ && !(ref $_ && builtin::refaddr($_) ne builtin::refaddr($self))
defined $_
ref $_
builtin::refaddr($_) ne builtin::refaddr($self)
Truth table0%0/4
A && not(B && C)
A= defined $_B= ref $_C= builtin::refaddr($_) ne builtin::refaddr($self)
| |||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||
| 478 | =head2 autogenerated PACKAGE | ||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||
| 480 | Returns true if the package was autogenerated by a classloader. | ||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||
| 482 | =cut | ||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | sub autogenerated { | ||||||||||||||||||||||||||||||||
|
Subroutine
autogenerated: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 485 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 486 | 0 | my $classname = shift; | |||||||||||||||||||||||||||||||||
| 487 | 0 | return $AUTOGENERATED{$classname}; | |||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||
| 490 | =head1 WRITING YOUR OWN CLASSES | ||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||
| 492 | If you require more functionality than is provided by the classes created by | ||||||||||||||||||||||||||||||||||
| 493 | ClassLoader (which you'll almost certainly need to do if you want an | ||||||||||||||||||||||||||||||||||
| 494 | application that does more than display a pretty Pony) then you should create a | ||||||||||||||||||||||||||||||||||
| 495 | class with the appropriate name and add your extra logic to it. | ||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||
| 497 | For example you will almost certainly want to write your own | ||||||||||||||||||||||||||||||||||
| 498 | dispatcher, so something like: | ||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||
| 500 | package MyApp::Dispatcher; | ||||||||||||||||||||||||||||||||||
| 501 | use Jifty::Dispatcher -base; | ||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||
| 503 | If you want to add some application specific behaviour to a model's | ||||||||||||||||||||||||||||||||||
| 504 | collection class, say for the User model, create F<UserCollection.pm> | ||||||||||||||||||||||||||||||||||
| 505 | in your applications Model directory. | ||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||
| 507 | package MyApp::Model::UserCollection; | ||||||||||||||||||||||||||||||||||
| 508 | use base 'MyApp::Collection'; | ||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||
| 510 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||
| 512 | L<Jifty> and just about every other class that this provides an empty override for. | ||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||
| 514 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||
| 516 | Jifty is Copyright 2005-2010 Best Practical Solutions, LLC. | ||||||||||||||||||||||||||||||||||
| 517 | Jifty is distributed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||
| 519 | =cut | ||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||
| 521 | 113 | 1; | |||||||||||||||||||||||||||||||||