Advertisement
gabrielvml

Untitled

Jan 18th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.72 KB | None | 0 0
  1. # MyApp.pl
  2.  
  3. my $model = MyApp::Model->new
  4.  
  5. ###########################
  6. # Database initialization #
  7. ###########################
  8. app->attr( 'db' => sub { $model->db } ); # Does the connection
  9. helper 'db' => sub { shift->app->db };
  10.  
  11.  
  12.  
  13. package MyApp::Model;
  14.  
  15. ######################################
  16. # Returns Database Connection Object #
  17. ######################################
  18. sub db {
  19.   my $self = shift;
  20.   $self->{db} = DBIx::Custom->connect(
  21.                   dsn      => $config->{db}->{dbi_dsn},
  22.                   user     => $config->{db}->{username},
  23.                   password => $config->{db}->{password},
  24.                   option   => { mysql_enable_utf8 => 1 }
  25.   ) if !$self->{db};
  26.   return $self->{db};
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement