On 13/09/2007, <b class="gmail_sendername">Ian Docherty</b> <<a href="mailto:catalyst@iandocherty.com">catalyst@iandocherty.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
My application has (effectively, subject to some cut and paste) the<br>following.<br><br>################<br><br>package MyApp::Schema;<br><br>use strict;<br>use warning;<br><br>use base qw(DBIx::Class::Schema);<br><br>__PACKAGE__->load_classes(qw(
<br> UsedPassword<br>));<br>1;<br><br>################<br><br>package MyApp::Schema::UsedPassword;<br><br>use strict;<br>use warning;<br><br>use base qw(DBIx::Class);<br><br>__PACKAGE__->load_components(qw(PK::Auto Core));
<br>__PACKAGE__->table('used_password');<br>__PACKAGE__->add_columns(qw(id user password));<br>__PACKAGE__->set_primary_key('id');<br><br>sub create_limited {<br> my ($self, $user, $password) = @_;
<br><br> # password checking logic here<br>}<br>1;<br><br>################<br><br>package MyApp::Model::DBIC;<br><br>use strict;<br>use warning;<br><br>use base qw(Catalyst::Model::DBIC::Schema);<br><br>__PACKAGE__->config(
<br> schema_class => 'MyApp::Schema',<br> connect_info => [<br> MyApp->config->{db},<br> MyApp->config->{db_user},<br> MyApp->config->{db_password},<br> {AutoCommit => 1, quote_char => '`', name_sep => '.'},
<br> ]);<br>1;<br><br>################<br><br>As I mentioned, if I try to do a call to<br>$c->model('DBIC::UsedPassword')->create_limited( ... ); I get the fatal<br>error<br><br>Can't locate object method "create_limited" via package
<br>"DBIx::Class::ResultSet<br><br>Which is why I think this is not the approach, unless you know otherwise?</blockquote><div><br>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:
<br><br>my $used_password = $c->model('DBIC::UsedPassword')->create( { user => 'user', password => 'password' } );<br>$used_password->foo_method()<br><br>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:
<br><br>package MyApp::Schema::UsedPassword;<br>...<br><br>sub new {<br> my ( $class, $attrs ) = @_;<br> my $user = $attrs->{user};<br> my $password = $attrs->{password};<br> <br> # password checking logic here
<br> <br> my $new = $class->next::method($attrs);<br> return $new;<br>}<br><br>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.
<br><br>Hope the above is useful.<br></div></div>