File Coverage

blib/lib/Pinto/Schema.pm
Criterion Covered Total %
statement 54 68 79.4
branch 0 2 0.0
condition 40 56 71.4
subroutine 13 16 81.2
pod 1 5 20.0
total 108 147 73.4


line stmt bran cond sub pod time code
1 56     56   2511305 use utf8;
  55         166  
  58         500  
2              
3             package Pinto::Schema;
4              
5             # Created by DBIx::Class::Schema::Loader
6             # DO NOT MODIFY THE FIRST PART OF THIS FILE
7              
8 56     54   2330 use Moose;
  54         105  
  54         385  
9 54     54   333494 use MooseX::MarkAsMethods autoclean => 1;
  54         42592  
  54         423  
10             extends 'DBIx::Class::Schema';
11              
12             __PACKAGE__->load_namespaces;
13              
14             # Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-04-29 01:03:56
15             # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yRlbDgtAuKaDHF9i1Kwqsg
16             #-------------------------------------------------------------------------------
17              
18             # ABSTRACT: The DBIx::Class::Schema for Pinto
19              
20             #-------------------------------------------------------------------------------
21              
22             our $VERSION = '0.13'; # VERSION
23              
24             #-------------------------------------------------------------------------------
25              
26 54     54   207523 use MooseX::SetOnce;
  54         598413  
  54         1992  
27              
28 54     54   1628 use Pinto::Util qw(decamelize throw);
  54         120  
  54         3306  
29              
30             #-------------------------------------------------------------------------------
31              
32 54     54   861 use Readonly;
  54         107  
  54         17820  
33             Readonly our $SCHEMA_VERSION => 1;
34 1     1 1 8 sub schema_version { return $SCHEMA_VERSION }
35              
36             #-------------------------------------------------------------------------------
37              
38             has repo => (
39             is => 'rw',
40             isa => 'Pinto::Repository',
41             traits => [qw(SetOnce)],
42             weak_ref => 1,
43             );
44              
45             #-------------------------------------------------------------------------------
46              
47             sub set_db_version {
48 0     0 0 0 my ($self) = @_;
49              
50             # NOTE: SQLite only permits integers for the user_version.
51             # The decimal portion of any float will be truncated.
52 0         0 my $version = $self->schema_version;
53 0         0 my $dbh = $self->storage->dbh;
54              
55 0         0 $dbh->do("PRAGMA user_version = $version");
56              
57 0         0 return;
58             }
59              
60             #-------------------------------------------------------------------------------
61              
62             sub get_db_version {
63 0     0 0 0 my ($self) = @_;
64              
65 0         0 my $dbh = $self->storage->dbh;
66              
67 0         0 my @version = $dbh->selectrow_array('PRAGMA user_version');
68              
69 0         0 return $version[0];
70             }
71              
72             #-------------------------------------------------------------------------------
73              
74             sub assert_db_version_ok {
75 0     0 0 0 my ($self) = @_;
76              
77 0         0 my $schema_version = $self->schema_version;
78 0         0 my $db_version = $self->get_db_version;
79              
80 0 0       0 throw "Database version ($db_version) and schema version ($schema_version) do not match"
81             if $db_version != $schema_version;
82              
83 0         0 return $self;
84             }
85              
86             #-------------------------------------------------------------------------------
87              
88             sub resultset_names {
89 54     54 0 170 my ($class) = @_;
90              
91 54         120 my @resultset_names = sort keys %{ $class->source_registrations };
  54         1195  
92              
93 54         1768 return @resultset_names;
94             }
95              
96             #-------------------------------------------------------------------------------
97              
98             for my $rs ( __PACKAGE__->resultset_names ) {
99              
100             ## no critic
101              
102 54     54   360 no strict 'refs';
  54         122  
  54         9091  
103             my $rs_decameled = decamelize($rs);
104              
105             my $rs_method_name = __PACKAGE__ . "::${rs_decameled}_rs";
106 192     192   1477 *{$rs_method_name} = eval "sub { return \$_[0]->resultset('$rs') }";
  436         3657  
  380         2799  
  367         2713  
  265         1918  
  284         2080  
  237         1735  
107              
108             my $create_method_name = __PACKAGE__ . "::create_${rs_decameled}";
109 76     76   2306 *{$create_method_name} = eval "sub { return \$_[0]->$rs_method_name->create(\$_[1]) }";
  60         2070  
  95         3293  
  65         2087  
  123         4019  
  97         3517  
  70         1785  
110              
111             my $search_method_name = __PACKAGE__ . "::search_${rs_decameled}";
112 74   50 74   1656 *{$search_method_name} = eval "sub { return \$_[0]->$rs_method_name->search(\$_[1] || {}, \$_[2] || {}) }";
  116   100     2778  
  96   50     9079  
  111   100     2404  
  99   50     9347  
  83   100     1729  
  43   50     931  
      100        
      50        
      100        
      50        
      50        
      50        
      50        
113              
114             my $find_method_name = __PACKAGE__ . "::find_${rs_decameled}";
115 56   50 56   1170 *{$find_method_name} = eval "sub { return \$_[0]->$rs_method_name->find(\$_[1] || {}, \$_[2] || {}) }";
  104   100     2270  
  100   50     2103  
  85   100     1823  
  103   50     2193  
  71   100     1482  
  76   50     1776  
      100        
      50        
      100        
      50        
      100        
      50        
      100        
116              
117             ## use critic
118             }
119              
120             #-------------------------------------------------------------------------------
121              
122             __PACKAGE__->meta->make_immutable;
123              
124             #-------------------------------------------------------------------------------
125             1;
126              
127             __END__
128              
129             =pod
130              
131             =encoding UTF-8
132              
133             =for :stopwords Jeffrey Ryan Thalhammer
134              
135             =head1 NAME
136              
137             Pinto::Schema - The DBIx::Class::Schema for Pinto
138              
139             =head1 VERSION
140              
141             version 0.13
142              
143             =head1 AUTHOR
144              
145             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
146              
147             =head1 COPYRIGHT AND LICENSE
148              
149             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
150              
151             This is free software; you can redistribute it and/or modify it under
152             the same terms as the Perl 5 programming language system itself.
153              
154             =cut