[Catalyst] Some guidance needed please
Will Hawes
wdhawes at gmail.com
Thu Sep 13 13:57:15 GMT 2007
On 13/09/2007, Ian Docherty <catalyst at iandocherty.com> wrote:
>
> My application has (effectively, subject to some cut and paste) the
> following.
>
> ################
>
> package MyApp::Schema;
>
> use strict;
> use warning;
>
> use base qw(DBIx::Class::Schema);
>
> __PACKAGE__->load_classes(qw(
> UsedPassword
> ));
> 1;
>
> ################
>
> package MyApp::Schema::UsedPassword;
>
> use strict;
> use warning;
>
> use base qw(DBIx::Class);
>
> __PACKAGE__->load_components(qw(PK::Auto Core));
> __PACKAGE__->table('used_password');
> __PACKAGE__->add_columns(qw(id user password));
> __PACKAGE__->set_primary_key('id');
>
> sub create_limited {
> my ($self, $user, $password) =3D @_;
>
> # password checking logic here
> }
> 1;
>
> ################
>
> package MyApp::Model::DBIC;
>
> use strict;
> use warning;
>
> use base qw(Catalyst::Model::DBIC::Schema);
>
> __PACKAGE__->config(
> schema_class =3D> 'MyApp::Schema',
> connect_info =3D> [
> MyApp->config->{db},
> MyApp->config->{db_user},
> MyApp->config->{db_password},
> {AutoCommit =3D> 1, quote_char =3D> '`', name_sep =3D> '.'},
> ]);
> 1;
>
> ################
>
> As I mentioned, if I try to do a call to
> $c->model('DBIC::UsedPassword')->create_limited( ... ); I get the fatal
> error
>
> Can't locate object method "create_limited" via package
> "DBIx::Class::ResultSet
>
> Which is why I think this is not the approach, unless you know otherwise?
Whoops, my bad. $c->model() does indeed return a DBIx::Class::ResultSet, so
you would need to retrieve/create an instance of your UsedPassword class
from the resultset in order to call any methods on it:
my $used_password =3D $c->model('DBIC::UsedPassword')->create( { user =3D>
'user', password =3D> 'password' } );
$used_password->foo_method()
Having said that, if I understand correctly what you are trying to do, you
probably don't want a create_limited method at all. I think you need to
override the new() method in your UsedPassword class and perform the checks
there instead:
package MyApp::Schema::UsedPassword;
...
sub new {
my ( $class, $attrs ) =3D @_;
my $user =3D $attrs->{user};
my $password =3D $attrs->{password};
# password checking logic here
my $new =3D $class->next::method($attrs);
return $new;
}
Also (and this may have been a typo on your part, but just in case), please
note it's "use warnings" not "use warning" to enable warnings in Perl.
Hope the above is useful.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070913/22696=
69b/attachment.htm
More information about the Catalyst
mailing list