« tutorial/lib/MyApp/Controller/User/DBIC.pm
↑ Summary
tutorial/lib/MyApp/Controller/Calculator.pm »
| 1 | # | ||||||||||
| 2 | # This file is part of CatalystX-ExtJS | ||||||||||
| 3 | # | ||||||||||
| 4 | # This software is Copyright (c) 2011 by Moritz Onken. | ||||||||||
| 5 | # | ||||||||||
| 6 | # This is free software, licensed under: | ||||||||||
| 7 | # | ||||||||||
| 8 | # The (three-clause) BSD License | ||||||||||
| 9 | # | ||||||||||
| 10 | package | ||||||||||
| 11 | MyApp::Model::DBIC; | ||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | extends 'Catalyst::Model::DBIC::Schema'; | |||||||||
| 15 | |||||||||||
| 16 | 1 | __PACKAGE__->config({ | |||||||||
| 17 | schema_class => 'MyApp::Schema', | ||||||||||
| 18 | connect_info => ['dbi:SQLite:dbname=:memory:'] | ||||||||||
| 19 | }); | ||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | 1 | ▶ | after BUILD => sub { | ||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=22.3
| |||||||||||
| 23 | 1 | my $self = shift; | |||||||||
| 24 | 1 | my $schema = $self->schema; | |||||||||
| 25 | 1 | ▶ | eval('use SQL::Translator 0.09003;'); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 1 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | my $sql; | |||||||||
| 28 | { | ||||||||||
| 29 | 0 | local $/; | |||||||||
| 30 | 0 | open( my $fh, 't/sqlite.sql' ); | |||||||||
| 31 | 0 | $sql = <$fh>; | |||||||||
| 32 | } | ||||||||||
| 33 | 0 | for my $chunk ( split( /;\s*\n+/, $sql ) ) { | |||||||||
| 34 | 0 | ▶ | if ( $chunk =~ / ^ (?! --\s* ) \S /xm ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | { # there is some real sql in the chunk - a non-space at the start of the string which is not a comment | ||||||||||
| 36 | 0 | ▶ | $schema->storage->dbh->do($chunk) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | or print "Error on SQL: $chunk\n"; | ||||||||||
| 38 | } | ||||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | else { | ||||||||||
| 42 | 1 | ▶ | unlink('t/sqlite.sql') if(-e 't/sqlite.sql'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 1 | $schema->deploy; | |||||||||
| 44 | 1 | $schema->create_ddl_dir( ['SQLite'], undef, './', undef, | |||||||||
| 45 | { add_drop_table => 0 } ); | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 1 | $schema->resultset('User')->create({email => 'lisa@simpsons.com', first => 'Lisa', last => 'Simpson' }); | |||||||||
| 49 | 1 | $schema->resultset('User')->create({email => 'bart@simpsons.com', first => 'Bart', last => 'Simpson' }); | |||||||||
| 50 | 1 | $schema->resultset('User')->create({email => 'maggie@simpsons.com', first => 'Maggie', last => 'Simpson' }); | |||||||||
| 51 | 1 | $schema->resultset('User')->create({email => 'homer@simpsons.com', first => 'Homer', last => 'Simpson' }); | |||||||||
| 52 | 1 | $schema->resultset('User')->create({email => 'marge@simpsons.com', first => 'Marge', last => 'Simpson' }); | |||||||||
| 53 | 1 | }; | |||||||||
| 54 | |||||||||||
| 55 | 1 | 1; | |||||||||