On Dec 16, 2007 10:25 AM, Carl Franks <[EMAIL PROTECTED]> wrote:
> On 16/12/2007, Zbigniew Lukasiak <[EMAIL PROTECTED]> wrote:
> > Thanks for the explanation. Is it possible to decouple it from
> > Catalyst by putting the schema on the stash?
> > I know FormFu is mostly used with Catalyst - but you never know and
> > beside that it would simplify testing.
>
> Yes, I initially thought it not too dependant on Catalyst - you just
> need an object in $form->stash->{catalyst} that supports a model()
> method - but it makes sense to not have to bother with that.
>
> How about:
> * if db: { model: x } is set, do $db = stash->{catalyst}->model(
> args->{db}{model} )
> * else do $db = stash->{ args->{db}{stash} }
>
> * and if db: { schema: x } is set, do $db = $db->resultset(
> args->{db}{schema} )
>
> This lets you put either your model or table schema on the stash.
>
> Carl
>
This is what I do:
sub get_rs {
my $self = shift;
return $self->{_resultset} if $self->{_resultset};
# get stash
my $stash = $self->form->stash;
my $rs;
if ( ( my $c = $stash->{context} ) && $self->model ) {
$rs = $c->model( $self->model )
or croak "\$c->model('@{[$self->model]}') does not exist\n";
}
elsif ( $stash->{schema} && $self->resultset ) {
$rs = $stash->{schema}->resultset( $self->resultset )
or croak "Resulset '@{[$self->resultset]}' could not be
loaded.";
}
else {
my $msg
= 'need a Catalyst context or a DBIC schema in the stash'
. ' and the respective model or resultset'
. ' parameter in the form config file.';
warn "@{[__PACKAGE__]}: $msg\n";
$self->return_error($msg);
return 0;
}
return $self->{_resultset} = $rs;
}
--
Jonas
_______________________________________________
HTML-FormFu mailing list
[email protected]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu