[Catalyst-commits] r6739 - /
trunk/Catalyst-Manual/lib/Catalyst/Manual
zarquon at dev.catalyst.perl.org
zarquon at dev.catalyst.perl.org
Fri Aug 24 23:45:01 GMT 2007
Author: zarquon
Date: 2007-08-24 23:45:01 +0100 (Fri, 24 Aug 2007)
New Revision: 6739
Modified:
/
trunk/Catalyst-Manual/lib/Catalyst/Manual/Cookbook.pod
Log:
r11506 at zaphod: kd | 2007-08-25 08:01:56 +1000
cookbook patch thanks to bits
Property changes on:
___________________________________________________________________
Name: svk:merge
- 1b129c88-ebf4-0310-add9-f09427935aba:/local/catalyst:4278
1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst:11499
3b9770f9-e80c-0410-a7de-cd203d167417:/local/catalyst:3514
dd8ad9ea-0304-0410-a433-df5f223e7bc0:/local/Catalyst:6909
+ 1b129c88-ebf4-0310-add9-f09427935aba:/local/catalyst:4278
1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst:11506
3b9770f9-e80c-0410-a7de-cd203d167417:/local/catalyst:3514
dd8ad9ea-0304-0410-a433-df5f223e7bc0:/local/Catalyst:6909
Modified: trunk/Catalyst-Manual/lib/Catalyst/Manual/Cookbook.pod
===================================================================
--- trunk/Catalyst-Manual/lib/Catalyst/Manual/Cookbook.pod 2007-08-24 18:11:38 UTC (rev 6738)
+++ trunk/Catalyst-Manual/lib/Catalyst/Manual/Cookbook.pod 2007-08-24 22:45:01 UTC (rev 6739)
@@ -635,6 +635,38 @@
See L<Catalyst::Model::DBIC::Schema>.
+=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
More information about the Catalyst-commits
mailing list