Skip to content

issm/p5-Amon2-Plugin-Model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

Amon2::Plugin::Model - model-class loader plugin for Amon2

SYNOPSIS

# 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();

DESCRIPTION

Amon2::Plugin::Model is model-class loader plugin for Amon2.

PLUGIN CONFIG

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'

AUTHOR

issm <[email protected]>

SEE ALSO

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

POD ERRORS

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'

About

model-class loader plugin for Amon2

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages