On 13/09/2007, Ian Docherty 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) = @_;
# password checking logic here
}
1;
################
package MyApp::Model::DBIC;
use strict;
use warning;
use base qw(Catalyst::Model::DBIC::Schema);
__PACKAGE__->config(
schema_class => 'MyApp::Schema',
connect_info => [
MyApp->config->{db},
MyApp->config->{db_user},
MyApp->config->{db_password},
{AutoCommit => 1, quote_char => '`', name_sep => '.'},
]);
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?
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) = @_;
# password checking logic here
}
1;
################
package MyApp::Model::DBIC;
use strict;
use warning;
use base qw(Catalyst::Model::DBIC::Schema);
__PACKAGE__->config(
schema_class => 'MyApp::Schema',
connect_info => [
MyApp->config->{db},
MyApp->config->{db_user},
MyApp->config->{db_password},
{AutoCommit => 1, quote_char => '`', name_sep => '.'},
]);
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 = $c->model('DBIC::UsedPassword')->create( { user =>
'user', password => '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 ) = @_;
my $user = $attrs->{user};
my $password = $attrs->{password};
# password checking logic here
my $new = $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/2269669b/attachment.htm
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070913/2269669b/attachment.htm