| 1 | package App::Sandy::DB; | ||||||||||
| 2 | # ABSTRACT: Singleton class to manage database | ||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use App::Sandy::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use App::Sandy::DB::Schema; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use MooseX::Singleton; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Path::Class 'file'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | our $VERSION = '0.25'; # VERSION | |||||||||
| 10 | |||||||||||
| 11 | 1 | has 'schema' => ( | |||||||||
| 12 | is => 'ro', | ||||||||||
| 13 | isa => 'App::Sandy::DB::Schema', | ||||||||||
| 14 | builder => '_build_schema', | ||||||||||
| 15 | lazy_build => 1, | ||||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub _build_schema { | ||||||||
|
Subroutine
_build_schema: not called CC=4 SCAR=30.0
| |||||||||||
| 19 | 0 | my $self = shift; | |||||||||
| 20 | |||||||||||
| 21 | # Hardcoded paths for database | ||||||||||
| 22 | 0 | my $DB = 'db.sqlite3'; | |||||||||
| 23 | 0 | my @DB_PATH = ( | |||||||||
| 24 | file(__FILE__)->dir->parent->parent->parent->file('share', 'assets'), | ||||||||||
| 25 | file(__FILE__)->dir->parent->parent->file('auto', 'share', 'dist', 'App-Sandy') | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | # The chosen one | ||||||||||
| 29 | 0 | my $db; | |||||||||
| 30 | |||||||||||
| 31 | 0 | for my $path (@DB_PATH) { | |||||||||
| 32 | # The chosen one | ||||||||||
| 33 | 0 | my $file = file($path, $DB); | |||||||||
| 34 | 0 | ▶ | if (-f $file) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | $db = $file; | |||||||||
| 36 | 0 | last; | |||||||||
| 37 | } | ||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | die "$DB not found in @DB_PATH" unless defined $db; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | |||||||||||
| 42 | 0 | return App::Sandy::DB::Schema->connect( | |||||||||
| 43 | "dbi:SQLite:$db", | ||||||||||
| 44 | "", | ||||||||||
| 45 | "", | ||||||||||
| 46 | { | ||||||||||
| 47 | RaiseError => 1, | ||||||||||
| 48 | PrintError => 0, | ||||||||||
| 49 | on_connect_do => 'PRAGMA foreign_keys = ON' | ||||||||||
| 50 | } | ||||||||||
| 51 | ); | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | __END__ | ||||||||||