Amon2::Plugin::Model - model-class loader plugin for Amon2
# your Amon2 application
package YourApp;
use parent 'Amon2';
__PACKAGE__->load_plugin('Model');
# or
__PACKAGE__->load_plugin('Model' => $plugin_conf);
...
# your model class
package YourApp::Model::Foo;
sub new {
# context object is passed as parameter "c"
my ($class, %params) = @_;
return bless \%params, $class;
}
sub c { shift->{c} }
sub hello {
return 'hello';
}
sub search {
my $self = shift;
my $dbh = $self->c->dbh;
my $sth = $dbh->prepare_cached(...);
$sth->execute(...);
...
}
# in your code
my $c = YourApp->bootstrap();
my $model = $c->model('Foo' => { foo => 1 });
print $model->{foo}; # 1
print $model->hello(); # 'hello'
$model->search();
Amon2::Plugin::Model is model-class loader plugin for Amon2.
- store_name : Bool
-
# your Amon2 application package YourApp; ... __PACKAGE__->load_plugin('Model' => {store_name => 1}); # your model package YourApp::Model::Foo; sub new { my ($class, %args) = @_; bless \%args, $class; } # in your code print $c->model('Foo')->{name}; # 'Foo' print $c->model('+YourApp::Model::Foo')->{name}; # '+YourApp::Model::Foo'
issm <[email protected]>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Hey! The above document had some coding errors, which are explained below:
- Around line 124:
-
Unknown directive: =over4
- Around line 126:
-
'=item' outside of any '=over'