blib/script/narada-setup-mysql

filter: Statementstmt 65.6% 44 / 67 Branchbran 5.5% 1 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 82.3% 14 / 17 Podpod n/a totaltotal 53.1% 59 / 111 CC 12 SCAR 39.7
CC
12
Cov
49%
main
132.0
import_sql
6.0
err
2.0
CRAP 52.9
↑ Summary blib/script/narada-mysqldump »
1 #!/usr/bin/env perl
2 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = 'v2.3.4';
8  
9 2 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use lib "$FindBin::Bin/../lib/perl5";
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Narada;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Narada::Config qw( get_config_line get_db_config );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use constant IS_NARADA => Narada::detect() eq 'narada';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use constant CONFIG_DIR => IS_NARADA ? 'mysql' : 'db';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use constant SQL_DIR => IS_NARADA ? 'var/mysql' : 'var/sql';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use constant SCHEME => SQL_DIR.'/db.scheme.sql';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 2 ▶main(@ARGV) if !caller;
Branch: 1 branch
BranchTrueFalseTotal
unless &CORE::GLOBAL::caller() 0 2 2
23  
24  
25 0 ▶sub err { die "narada-setup-mysql: @_\n" }
Subroutine err: not called CC=1 SCAR=6.9
26  
27 sub main {
28 0 ▶ die "Usage: narada-setup-mysql [--clean]\n"
Subroutine main: not called CC=11 SCAR=48.8
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 or @_ == 1 and $_[0] ne "--clean" 0 0 0
Condition0%0/6
@_ > 1 or @_ == 1 and $_[0] ne "--clean"
l!l&&r!l&&!r
000
@_ == 1 and $_[0] ne "--clean"
!ll&&!rl&&r
000
MC/DC0%0/3
@_ > 1 or @_ == 1 and $_[0] ne "--clean"
@_ > 1 @_ == 1 $_[0] ne "--clean"
Truth table0%0/4
A or B and C
A= @_ > 1B= @_ == 1C= $_[0] ne "--clean"
ABCresult
1XX1
0111
00X0
0100
29 if (@_ > 1)
30 || (@_ == 1 && $_[0] ne '--clean');
31  
32 0 ▶ my $db = get_db_config() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $db = get_db_config() or return 0 0 0
33 $::dbh = DBI->connect($db->{dsn_nodb}, $db->{login}, $db->{pass},
34 0 ▶ {RaiseError=>1}) or err DBI->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$main::dbh = "DBI"->connect($db->{"dsn_nodb"}, $db->{"login"}, $db->{"pass"}, {"RaiseError", 1}) or "DBI"->err->errstr 0 0 0
35  
36 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
37 0 path('var/use/mysql')->remove;
38 0 $::dbh->do('DROP DATABASE IF EXISTS `'.$db->{db}.q{`});
39 }
40 else {
41 0 if (IS_NARADA) {
42 0 path('var/use/mysql')->touch;
43 }
44 0 $::dbh->do('CREATE DATABASE IF NOT EXISTS `'.$db->{db}.q{`});
45 0 $::dbh->do('USE `'.$db->{db}.q{`});
46 0 ▶ if (0 < $::dbh->prepare('SHOW TABLES')->execute()) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 < $main::dbh->prepare("SHOW TABLES")->execute) 0 0 0
47 0 err 'SQL files not imported because database does not empty';
48 }
49 0 ▶ if (-f SCHEME) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "var/mysql/db.scheme.sql") 0 0 0
50 0 import_sql(SCHEME);
51 0 ▶ for (grep {-f && $_ ne SCHEME} glob SQL_DIR.'/*.sql') {
Branch: 1 branch
BranchTrueFalseTotal
-f $_ and $_ ne "var/mysql/db.scheme.sql" 0 0 0
52 0 import_sql($_);
53 }
54 }
55 }
56  
57 0 return;
58 }
59  
60 sub import_sql {
61 0 ▶ my ($file) = @_;
Subroutine import_sql: not called CC=2 SCAR=17.9
62 0 warn "Importing $file...\n";
63 0 ▶ system("narada-mysql <\Q$file\E") == 0 or err 'Failed to import '.$file;
Branch: 1 branch
BranchTrueFalseTotal
system("narada-mysql <\Q$file\E") == 0 or err('Failed to import ' . $file) 0 0 0
64 0 return;
65 }
66  
67  
68 2 1; # Magic true value required at end of module
69 __END__
70  
71 =encoding utf8
72  
73 =head1 NAME
74  
75 narada-setup-mysql - initialize project database
76  
77  
78 =head1 VERSION
79  
80 This document describes narada-setup-mysql version v2.3.4
81  
82  
83 =head1 USAGE
84  
85 narada-setup-mysql [--clean]
86  
87  
88 =head1 DESCRIPTION
89  
90 Should be executed in project deploy directory (or Narada 1.x project root
91 directory).
92  
93 Initialize/drop your Narada project's MySQL database.
94  
95 If "config/mysql/db" absent or empty do nothing.
96  
97 When executed without params will create database (if needed) and load sql dumps
98 into database (if C<var/mysql/db.scheme.sql> exist).
99  
100 When executed with --clean option will drop project's database with all tables.
101  
102  
103 =head1 CONFIGURATION AND ENVIRONMENT
104  
105 config/mysql/db
106 config/mysql/login
107 config/mysql/pass
108 config/mysql/host
109 config/mysql/port
110 var/mysql/db.scheme.sql
111 var/mysql/*.sql
112 var/use/mysql
113  
114 Narada 1.x project use C<config/db/> instead of C<config/mysql/>,
115 and C<var/sql/> instead of C<var/mysql/>.
116  
117  
118 =head1 SUPPORT
119  
120 =head2 Bugs / Feature Requests
121  
122 Please report any bugs or feature requests through the issue tracker
123 at L<https://github.com/powerman/Narada/issues>.
124 You will be notified automatically of any progress on your issue.
125  
126 =head2 Source Code
127  
128 This is open source software. The code repository is available for
129 public review and contribution under the terms of the license.
130 Feel free to fork the repository and submit pull requests.
131  
132 L<https://github.com/powerman/Narada>
133  
134 git clone https://github.com/powerman/Narada.git
135  
136 =head2 Resources
137  
138 =over
139  
140 =item * MetaCPAN Search
141  
142 L<https://metacpan.org/search?q=Narada>
143  
144 =item * CPAN Ratings
145  
146 L<http://cpanratings.perl.org/dist/Narada>
147  
148 =item * AnnoCPAN: Annotated CPAN documentation
149  
150 L<http://annocpan.org/dist/Narada>
151  
152 =item * CPAN Testers Matrix
153  
154 L<http://matrix.cpantesters.org/?dist=Narada>
155  
156 =item * CPANTS: A CPAN Testing Service (Kwalitee)
157  
158 L<http://cpants.cpanauthors.org/dist/Narada>
159  
160 =back
161  
162  
163 =head1 AUTHOR
164  
165 Alex Efros E<lt>powerman@cpan.orgE<gt>
166  
167  
168 =head1 COPYRIGHT AND LICENSE
169  
170 This software is Copyright (c) 2008-2016 by Alex Efros E<lt>powerman@cpan.orgE<gt>.
171  
172 This is free software, licensed under:
173  
174 The MIT (X11) License
175  
176  
177 =cut
↑ Summary blib/script/narada-mysqldump »