X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Manual.git;a=blobdiff_plain;f=lib%2FCatalyst%2FManual%2FCookbook.pod;h=192d3bdbee6c5cf6732d9110064637b783187a27;hp=2ce3a56f6b548b75af1e86fa636ca9e9425e6e5e;hb=15e1d0b201341bf72fbf027d1450bbddac49e80f;hpb=c718cfb669a068d7cfebc8b155ea1aec7d5cc84e diff --git a/lib/Catalyst/Manual/Cookbook.pod b/lib/Catalyst/Manual/Cookbook.pod index 2ce3a56..192d3bd 100644 --- a/lib/Catalyst/Manual/Cookbook.pod +++ b/lib/Catalyst/Manual/Cookbook.pod @@ -160,36 +160,27 @@ You configure your application with the C method in your application class. This can be hard-coded, or brought in from a separate configuration file. -=head3 Using YAML +=head3 Using Config::General -YAML is a method for creating flexible and readable configuration -files. It's a great way to keep your Catalyst application -configuration in one easy-to-understand location. +L is a method for creating flexible +and readable configuration files. It's a great way to keep your +Catalyst application configuration in one easy-to-understand location. -In your application class (e.g. C): +Now create C in your application home: - use YAML; - # application setup - __PACKAGE__->config( YAML::LoadFile(__PACKAGE__->config->{'home'} . '/myapp.yml') ); - __PACKAGE__->setup; - -Now create C in your application home: - - --- #YAML:1.0 - # DO NOT USE TABS FOR INDENTATION OR label/value SEPARATION!!! - name: MyApp + name MyApp # session; perldoc Catalyst::Plugin::Session::FastMmap - session: - expires: '3600' - rewrite: '0' - storage: '/tmp/myapp.session' + + expires 3600 + rewrite 0 + storage /tmp/myapp.session + # emails; perldoc Catalyst::Plugin::Email # this passes options as an array :( - email: - - SMTP - - localhost + Mail SMTP + Mail localhost This is equivalent to: @@ -208,7 +199,7 @@ This is equivalent to: # configure email sending __PACKAGE__->config->{email} = [qw/SMTP localhost/]; -See also L. +See also L. =head1 Skipping your VCS's directories @@ -635,6 +626,38 @@ Cat app as C. See L. +=head2 Create accessors to preload static data once per server instance + +When you have data that you want to load just once from the model at +server load instead of for each request, use mk_group_accessors to +create accessors and tie them to resultsets in your package that +inherits from DBIx::Class::Schema + + package My::Schema; + use base qw/DBIx::Class::Schema/; + __PACKAGE__->register_class('RESULTSOURCEMONIKER', + 'My::Schema::RESULTSOURCE'); + __PACKAGE__->mk_group_accessors('simple' => + qw(ACCESSORNAME1 ACCESSORNAME2 ACCESSORNAMEn)); + + sub connection { + my ($self, @rest) = @_; + $self->next::method(@rest); + # $self is now a live My::Schema object, complete with DB connection + + $self->ACCESSORNAME1([ $self->resultset('RESULTSOURCEMONIKER')->all ]); + $self->ACCESSORNAME2([ $self->resultset('RESULTSOURCEMONIKER')->search({ COLUMN => { '<' => '30' } })->all ]); + $self->ACCESSORNAMEn([ $self->resultset('RESULTSOURCEMONIKER')->find(1) ]); + } + + 1; + +and now in the controller, you can now access any of these without a +per-request fetch: + + $c->stash->{something} = $c->model('My::Schema')->schema->ACCESSORNAMEn; + + =head2 XMLRPC Unlike SOAP, XMLRPC is a very simple (and imo elegant) web-services