aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Catalyst
diff options
context:
space:
mode:
authorgroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2007-09-12 19:57:03 +0000
committergroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2007-09-12 19:57:03 +0000
commitf670cfd0d1ce4753a2c76b27cdc01e8471e4cc4a (patch)
tree4dacd893406f69701761ac2705433772005d117f /lib/Catalyst
parent7adfd53f17f66ffe93763e944ed1d3fc52a369dc (diff)
downloadreaction-f670cfd0d1ce4753a2c76b27cdc01e8471e4cc4a.tar.gz
reaction-f670cfd0d1ce4753a2c76b27cdc01e8471e4cc4a.zip
first checkin tests fail everywhere but demo works. yay?
Diffstat (limited to 'lib/Catalyst')
-rw-r--r--lib/Catalyst/Model/Reaction/InterfaceModel/DBIC.pm116
1 files changed, 116 insertions, 0 deletions
diff --git a/lib/Catalyst/Model/Reaction/InterfaceModel/DBIC.pm b/lib/Catalyst/Model/Reaction/InterfaceModel/DBIC.pm
new file mode 100644
index 0000000..bd75604
--- /dev/null
+++ b/lib/Catalyst/Model/Reaction/InterfaceModel/DBIC.pm
@@ -0,0 +1,116 @@
+package Catalyst::Model::Reaction::InterfaceModel::DBIC;
+
+use Reaction::Class;
+
+use Catalyst::Utils;
+use Catalyst::Component;
+use Class::MOP;
+
+#XXX so yeah, thisis kinda hacky. big whop though, i need it.
+#this may just all together go away in the future
+
+class DBIC, is 'Reaction::Object', is 'Catalyst::Component', which {
+
+ has '_schema' => (isa => 'DBIx::Class::Schema', is => 'ro', required => 1);
+
+ implements 'COMPONENT' => as {
+ my ($class, $app, $args) = @_;
+ my %cfg = %{ Catalyst::Utils::merge_hashes($class->config, $args) };
+
+ my $im_class = $cfg{im_class};
+ Class::MOP::load_class($im_class);
+
+ my $model_name = $class;
+ $model_name =~ s/^[\w:]+::(?:Model|M):://;
+
+ #XXXthis could be cut out later for a more elegant method
+ my @domain_models = $im_class->domain_models;
+ confess "Unable to locate domain model in ${im_class}"
+ if @domain_models < 1;
+ confess 'ModelBase does not yet support multiple domain models'
+ if @domain_models > 1;
+ my $domain_model = shift @domain_models;
+ my $schema_class = $domain_model->_isa_metadata;
+ Class::MOP::load_class($schema_class);
+
+ {
+ #I should probably MOPize this at some point maybe? nahhhh
+ #XXXMaybe I should just fix CRUDController and eliminate this shit period.
+ #pure bloat and namespace pollution
+ no strict 'refs';
+ foreach my $collection ( $im_class->parameter_attributes ){
+ my $classname = join '::', $class, $collection->name, 'ACCEPT_CONTEXT';
+ my $reader = $collection->get_read_method;
+ *$classname = sub{ $_[1]->model($model_name)->$reader };
+ }
+ }
+
+ my $params = $cfg{db_params} || {};
+ my $schema = $schema_class
+ ->connect($cfg{db_dsn}, $cfg{db_user}, $cfg{db_password}, $params);
+
+ return $class->new(_schema => $schema);
+ };
+
+ implements 'ACCEPT_CONTEXT' => as {
+ my ($self, $ctx) = @_;
+ return $self->CONTEXTUAL_CLONE($ctx) unless ref $ctx;
+ return $ctx->stash->{ref($self)} ||= $self->CONTEXTUAL_CLONE($ctx);
+ };
+
+ #XXXto do build in support for RestrictByUser natively or by subclass
+ implements 'CONTEXTUAL_CLONE' => as {
+ my ($self, $ctx) = @_;
+ my $schema = $self->_schema->clone;
+
+ my $im_class = $self->config->{im_class};
+
+ #XXXthis could be cut out later for a more elegant method
+ my @domain_models = $im_class->domain_models;
+ confess "Unable to locate domain model in ${im_class}"
+ if @domain_models < 1;
+ confess 'ModelBase does not yet support multiple domain models'
+ if @domain_models > 1;
+ my $domain_model = shift @domain_models;
+
+ return $im_class->new($domain_model->name => $schema);
+ };
+
+};
+
+
+1;
+
+=head1 NAME
+
+Catalyst::Model::Reaction::InterfaceModel::DBIC
+
+=head1 DESCRIPTION
+
+=head2 COMPONENT
+
+=head2 ACCEPT_CONTEXT
+
+=head2 CONTEXTUAL_CLONE
+
+=head1 CONFIG OPTIONS
+
+=head2 db_dsn
+
+=head2 db_user
+
+=head2 db_password
+
+=head2 db_params
+
+=head2 im_class
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut