« blib/lib/Amon2/Web.pm
↑ Summary
blib/lib/auto/share/dist/Amon2/flavor/Large/lib/__PATH__/__MONIKER__/ViewFunctions.pm »
| 1 | package <% $module %>; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use utf8; | ||
| 5 | our $VERSION='0.01'; | ||
| 6 | use 5.008001; | ||
| 7 | use <% $module %>::DB::Schema; | ||
| 8 | use <% $module %>::DB; | ||
| 9 | |||
| 10 | use parent qw/Amon2/; | ||
| 11 | # Enable project local mode. | ||
| 12 | __PACKAGE__->make_local_context(); | ||
| 13 | |||
| 14 | my $schema = <% $module %>::DB::Schema->instance; | ||
| 15 | |||
| 16 | sub db { | ||
| 17 | my $c = shift; | ||
| 18 | if (!exists $c->{db}) { | ||
| 19 | my $conf = $c->config->{DBI} | ||
| 20 | or die "Missing configuration about DBI"; | ||
| 21 | $c->{db} = <% $module %>::DB->new( | ||
| 22 | schema => $schema, | ||
| 23 | connect_info => [@$conf], | ||
| 24 | # I suggest to enable following lines if you are using mysql. | ||
| 25 | # on_connect_do => [ | ||
| 26 | # 'SET SESSION sql_mode=STRICT_TRANS_TABLES;', | ||
| 27 | # ], | ||
| 28 | ); | ||
| 29 | } | ||
| 30 | $c->{db}; | ||
| 31 | } | ||
| 32 | |||
| 33 | 1; | ||
| 34 | __END__ |