File Coverage

blib/lib/Pinto/Schema.pm
Criterion Covered Total %
statement 54 68 79.4
branch 0 2 0.0
condition 41 56 73.2
subroutine 13 16 81.2
pod 1 5 20.0
total 109 147 74.1


line stmt bran cond sub pod time code
1 58     58   2412223 use utf8;
  60         320  
  59         541  
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 55     54   2438 use Moose;
  54         114  
  54         412  
9 54     54   346132 use MooseX::MarkAsMethods autoclean => 1;
  54         45570  
  54         501  
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.14'; # VERSION
23              
24             #-------------------------------------------------------------------------------
25              
26 54     54   216470 use MooseX::SetOnce;
  54         592216  
  54         2144  
27              
28 54     54   1930 use Pinto::Util qw(decamelize throw);
  54         138  
  54         3549  
29              
30             #-------------------------------------------------------------------------------
31              
32 54     54   869 use Readonly;
  54         116  
  54         18677  
33             Readonly our $SCHEMA_VERSION => 1;
34 1     1 1 10 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 171 my ($class) = @_;
90              
91 54         116 my @resultset_names = sort keys %{ $class->source_registrations };
  54         1210  
92              
93 54         2043 return @resultset_names;
94             }
95              
96             #-------------------------------------------------------------------------------
97              
98             for my $rs ( __PACKAGE__->resultset_names ) {
99              
100             ## no critic
101              
102 54     54   406 no strict 'refs';
  54         143  
  54         9285  
103             my $rs_decameled = decamelize($rs);
104              
105             my $rs_method_name = __PACKAGE__ . "::${rs_decameled}_rs";
106 392     392   2568 *{$rs_method_name} = eval "sub { return \$_[0]->resultset('$rs') }";
  443         3099  
  181         1143  
  330         2540  
  332         2958  
  229         2975  
  254         1719  
107              
108             my $create_method_name = __PACKAGE__ . "::create_${rs_decameled}";
109 83     83   2179 *{$create_method_name} = eval "sub { return \$_[0]->$rs_method_name->create(\$_[1]) }";
  113         3809  
  78         2055  
  58         1438  
  54         1515  
  104         3622  
  96         2894  
110              
111             my $search_method_name = __PACKAGE__ . "::search_${rs_decameled}";
112 111   50 111   2283 *{$search_method_name} = eval "sub { return \$_[0]->$rs_method_name->search(\$_[1] || {}, \$_[2] || {}) }";
  59   100     8061  
  131   50     2807  
  112   100     6909  
  87   50     1774  
  28   100     580  
  94   50     1867  
      100        
      50        
      50        
      50        
      100        
      50        
      100        
113              
114             my $find_method_name = __PACKAGE__ . "::find_${rs_decameled}";
115 93   50 93   1865 *{$find_method_name} = eval "sub { return \$_[0]->$rs_method_name->find(\$_[1] || {}, \$_[2] || {}) }";
  75   100     1611  
  123   50     2445  
  56   100     1178  
  58   50     1204  
  82   100     1616  
  101   50     1925  
      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.14
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