File Coverage

lib/DBIx/Schema/Changelog/File/JSON.pm
Criterion Covered Total %
statement 20 20 100.0
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 28 29 96.5


line stmt bran cond sub pod time code
1             package DBIx::Schema::Changelog::File::JSON;
2              
3             =head1 NAME
4              
5             DBIx::Schema::Changelog::File::JSON - module for DBIx::Schema::Changelog::File to load changeset from JSON files.
6              
7             =head1 VERSION
8              
9             Version 0.8.0
10              
11             =cut
12              
13             our $VERSION = '0.8.0';
14              
15 1     1   804 use strict;
  1         2  
  1         44  
16 1     1   5 use warnings FATAL => 'all';
  1         2  
  1         52  
17 1     1   671 use Moose;
  1         472450  
  1         12  
18 1     1   7185 use JSON::Parse qw( json_file_to_perl );
  1         850  
  1         224  
19              
20             with 'DBIx::Schema::Changelog::File';
21              
22             has tpl_main => (
23             isa => 'Str',
24             is => 'ro',
25             default => q~{
26             "templates": {
27             "name": "tpl_std",
28             "columns": [
29             { "name": "id", "type": "integer", "notnull": 1, "primarykey": 1, "default": "inc" },
30             { "name": "name", "type": "varchar", "notnull": 1, "default": "current" },
31             { "name": "active", "type": "bool", "default": 1 },
32             { "name": "flag", "type": "timestamp", "default": "current", "notnull": 1 }
33             ]
34             },
35             "changelogs": [ "01" ]
36             }~,
37             );
38              
39             has tpl_sub => (
40             isa => 'Str',
41             is => 'ro',
42             default => q~[
43             {
44             "id": "001.01-maz",
45             "author": "Mario Zieschang",
46             "entries": [ { "type": "createtable", "name": "client", "columns": [ { "tpl": "tpl_std" } ] } ]
47             }
48             ]~,
49             );
50              
51             has ending => (
52             is => 'ro',
53             isa => 'Str',
54             default => '.json',
55             );
56              
57             =head1 SUBROUTINES/METHODS
58              
59             =over 4
60              
61             =item load
62              
63             Called to load defined JSON files
64              
65             =cut
66              
67             sub load{
68 2     2 1 15553 my ( $self, $file ) = @_;
69              
70 2         115 $file = $file.$self->ending();
71              
72 2 50       144 open my $rfh, '<', $file or die "can't open config file: $file $!";
73 2         272 print STDERR __PACKAGE__, ". Read changelog file '$file'. \n";
74            
75 2         17 return json_file_to_perl ($file);
76             }
77              
78 1     1   7 no Moose;
  1         2  
  1         6  
79             __PACKAGE__->meta->make_immutable;
80              
81             1; # End of DBIx::Schema::Changelog::File::JSON
82              
83             __END__
84              
85             =back
86              
87             =head1 AUTHOR
88              
89             Mario Zieschang, C<< <mario.zieschang at combase.de> >>
90              
91             =head1 LICENSE AND COPYRIGHT
92              
93             Copyright 2015 Mario Zieschang.
94              
95             This program is free software; you can redistribute it and/or modify it
96             under the terms of the the Artistic License (2.0). You may obtain a
97             copy of the full license at:
98              
99             L<http://www.perlfoundation.org/artistic_license_2_0>
100              
101             Any use, modification, and distribution of the Standard or Modified
102             Versions is governed by this Artistic License. By using, modifying or
103             distributing the Package, you accept this license. Do not use, modify,
104             or distribute the Package, if you do not accept this license.
105              
106             If your Modified Version has been derived from a Modified Version made
107             by someone other than you, you are nevertheless required to ensure that
108             your Modified Version complies with the requirements of this license.
109              
110             This license does not grant you the right to use any trademark, service
111             mark, trade name, or logo of the Copyright Holder.
112              
113             This license includes the non-exclusive, worldwide, free-of-charge
114             patent license to make, have made, use, offer to sell, sell, import and
115             otherwise transfer the Package with respect to any patent claims
116             licensable by the Copyright Holder that are necessarily infringed by the
117             Package. If you institute patent litigation (including a cross-claim or
118             counterclaim) against any party alleging that the Package constitutes
119             direct or contributory patent infringement, then this Artistic License
120             to you shall terminate on the date that such litigation is filed.
121              
122             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
123             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
124             THE IMPLIED WARRANTIES OF MERCHANT ABILITY, FITNESS FOR A PARTICULAR
125             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
126             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
127             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
128             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
129             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
130              
131             =cut