Galileo/DB/Deploy.pm

filter: Statementstmt 90.2% 65 / 72 Branchbran 50.0% 9 / 18 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 82.3% 14 / 17 Podpod 0.0% 0 / 6 totaltotal 76.7% 89 / 116 CC 11 SCAR 8.5
CC
11
Cov
82%
inject_sample_data
4.1
create_test_object
4.0
_build_temp_script_dir
2.1
CRAP 2.3
« Galileo/Page.pm ↑ Summary Galileo/User.pm »
1 package Galileo::DB::Deploy;
2 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶BEGIN{ extends 'DBIx::Class::DeploymentHandler' }
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # A wrapper class for DBICDH for use with Galileo
6  
7 3 ▶use Mojo::JSON 'j';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use File::ShareDir qw/dist_dir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use File::Copy::Recursive 'dircopy';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 has 'temp_script_dir' => (
15 is => 'rw',
16 lazy => 1,
17 builder => '_build_temp_script_dir',
18 );
19  
20 3 ▶sub _build_temp_script_dir {
Subroutine _build_temp_script_dir: called CC=2 SCAR=7.6
21 3 ▶ File::Temp->newdir( $ENV{KEEP_TEMP_DIR} ? (CLEANUP => 0) : () );
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'KEEP_TEMP_DIR'} ? : 0 3 3
22 }
23  
24 3 has 'real_script_dir' => (
25 is => 'rw',
26 lazy => 1,
27 builder => '_build_real_script_dir',
28 );
29  
30 3 ▶sub _build_real_script_dir {
Subroutine _build_real_script_dir: called CC=2 SCAR=7.2
31 3 my $dev_dir = File::Spec->catdir( qw/ lib Galileo files sql / );
32 3 ▶ -e $dev_dir ? $dev_dir : File::Spec->catdir( dist_dir('Galileo'), 'sql' );
Branch: 1 branch
BranchTrueFalseTotal
-e $dev_dir ? : 3 0 3
33 }
34  
35 3 has 'script_directory' => (
36 is => 'rw',
37 lazy => 1,
38 builder => '_build_script_directory',
39 );
40  
41 3 ▶sub _build_script_directory {
Subroutine _build_script_directory: called CC=2 SCAR=7.0
42 3 my $self = shift;
43 3 my $dir = $self->real_script_dir;
44 3 my $temp = $self->temp_script_dir;
45 3 ▶ dircopy $dir, $temp or die "Cannot copy from $dir to $temp";
Branch: 1 branch
BranchTrueFalseTotal
dircopy($dir, $temp) or die "Cannot copy from $dir to $temp" 3 0 3
46 3 return "$temp";
47 }
48  
49 3 has 'databases' => (
50 is => 'rw',
51 lazy => 1,
52 builder => '_build_databases',
53 );
54  
55 0 ▶sub _build_databases { [ shift->schema->storage->sqlt_type ] }
Subroutine _build_databases: not called CC=1 SCAR=6.9
56  
57 3 has '+force_overwrite' => (
58 default => 1,
59 );
60  
61 3 has '+ignore_ddl' => (
62 default => 1,
63 );
64  
65 3 ▶sub installed_version {
Subroutine installed_version: called CC=1 SCAR=0.0
Pod undocumented
66 3 my $self = shift;
67 3 return eval{ $self->database_version }
68 }
69  
70 3 ▶sub do_install {
Subroutine do_install: called CC=2 SCAR=7.1
Pod undocumented
71 3 my $self = shift;
72  
73 3 $self->prepare_install;
74 3 ▶ $self->install( @_ ? {version => shift} : () );
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 3 3
75 }
76  
77 0 ▶sub do_upgrade {
Subroutine do_upgrade: not called CC=1 SCAR=6.9
Pod undocumented
78 0 my $self = shift;
79  
80 0 $self->prepare_upgrade;
81 0 $self->upgrade;
82 }
83  
84 0 ▶sub has_admin_user {
Subroutine has_admin_user: not called CC=1 SCAR=6.9
Pod undocumented
85 0 my $self = shift;
86 0 return eval { $self->schema->resultset('User')->first }
87 }
88  
89 3 ▶sub inject_sample_data {
Subroutine inject_sample_data: called CC=4 SCAR=14.1
Pod undocumented
90 3 my $self = shift;
91 3 my $schema = $self->schema;
92  
93 3 ▶ my $user = shift or die "Must provide an admin username\n";
Branch: 1 branch
BranchTrueFalseTotal
my $user = shift() or die "Must provide an admin username\n" 3 0 3
94 3 ▶ my $pass = shift or die "Must provide a password for admin user\n";
Branch: 1 branch
BranchTrueFalseTotal
my $pass = shift() or die "Must provide a password for admin user\n" 3 0 3
95 3 ▶ my $full = shift || "Administrator";
Condition50%1/2
shift() || 'Administrator'
l!l
30
MC/DC0%0/1
shift() || 'Administrator'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
96  
97 3 my $admin = $schema->resultset('User')->create({
98 name => $user,
99 full => $full,
100 password => $pass,
101 is_author => 1,
102 is_admin => 1,
103 });
104  
105 3 $schema->resultset('Page')->create({
106 name => 'home',
107 title => 'Galileo CMS',
108 html => <<'HTML',
109 <h2>Welcome to your Galileo CMS site!</h2>
110  
111 <blockquote>
112 <p>Galileo Galilei was "an Italian physicist, mathematician, astronomer, and philosopher who played a major role in the Scientific Revolution." -- <a href="https://en.wikipedia.org/wiki/Galileo_Galilei">Wikipedia</a> </p>
113 </blockquote>
114  
115 <p>When he first turned the telescope to face Jupiter, he used modern technology to improve the world around him.</p>
116  
117 <p>Like the great scientist it is named for, Galileo CMS is not afraid to be very modern. Learn more about it on the <a href="/page/about">about</a> page.</p>
118  
119 <p><img src="/portrait.jpg" alt="Portrait of Galileo Galilei" title="" /></p>
120 HTML
121 md => <<'MARKDOWN',
122 ##Welcome to your Galileo CMS site!
123  
124 > Galileo Galilei was "an Italian physicist, mathematician, astronomer, and philosopher who played a major role in the Scientific Revolution." -- [Wikipedia](https://en.wikipedia.org/wiki/Galileo_Galilei)
125  
126 When he first turned the telescope to face Jupiter, he used modern technology to improve the world around him.
127  
128 Like the great scientist it is named for, Galileo CMS is not afraid to be very modern. Learn more about it on the [about](/page/about) page.
129  
130 ![Portrait of Galileo Galilei](/portrait.jpg)
131 MARKDOWN
132 author_id => $admin->user_id,
133 });
134  
135 3 my $about = $schema->resultset('Page')->create({
136 name => 'about',
137 title => 'About Galileo',
138 html => <<'HTML',
139 <p>Galileo CMS is built upon some great open source projects:</p>
140  
141 <ul>
142 <li><a href="http://perl.org">Perl</a> - if you haven't looked at Perl lately, give it another try!</li>
143 <li><a href="http://mojolicio.us">Mojolicious</a> - a next generation web framework for the Perl programming language</li>
144 <li><a href="http://www.dbix-class.org/">DBIx::Class</a> - an extensible and flexible Object/Relational Mapper written in Perl</li>
145 <li><a href="http://code.google.com/p/pagedown/">PageDown</a> (Markdown engine) - the version of Attacklab's Showdown and WMD as used on Stack Overflow and the other Stack Exchange sites</li>
146 <li><a href="http://twitter.github.com/bootstrap">Bootstrap</a> - the beautiful CSS/JS library from Twitter</li>
147 <li><a href="http://jquery.com/">jQuery</a> - because everything uses jQuery</li>
148 <li><a href="http://wavded.github.com/humane-js/">HumaneJS</a> - A simple, modern, browser notification system</li>
149 </ul>
150  
151 <p>Galileo is developed by <a href="https://github.com/jberger">Joel Berger</a>. <a href="https://github.com/jberger/Galileo">Fork it</a> on GitHub!</p>
152 HTML
153 md => <<'MARKDOWN',
154 Galileo CMS is built upon some great open source projects:
155  
156 * [Perl](http://perl.org) - if you haven't looked at Perl lately, give it another try!
157 * [Mojolicious](http://mojolicio.us) - a next generation web framework for the Perl programming language
158 * [DBIx::Class](http://www.dbix-class.org/) - an extensible and flexible Object/Relational Mapper written in Perl
159 * [PageDown](http://code.google.com/p/pagedown/) (Markdown engine) - the version of Attacklab's Showdown and WMD as used on Stack Overflow and the other Stack Exchange sites
160 * [Bootstrap](http://twitter.github.com/bootstrap) - the beautiful CSS/JS library from Twitter
161 * [jQuery](http://jquery.com/) - because everything uses jQuery
162 * [HumaneJS](http://wavded.github.com/humane-js/) - A simple, modern, browser notification system
163  
164 Galileo is developed by [Joel Berger](https://github.com/jberger). [Fork it](https://github.com/jberger/Galileo) on GitHub!
165 MARKDOWN
166 author_id => $admin->user_id,
167 });
168  
169 3 my $syntax = $schema->resultset('Page')->create({
170 name => 'syntax',
171 title => 'Syntax',
172 html => <<'HTML',
173 <h2>Highlighting</h2>
174  
175 <p>Default highlighter is <a href="http://highlightjs.org/">highlight.js</a>. But Galileo just generates HTML so if you want to see colorized output then you have to load javascript and css.</p>
176  
177 <pre class="hljs"><code class="language-xml">&lt;!-- example --&gt;
178 &lt;link rel="stylesheet" href="http://yandex.st/highlightjs/8.0/styles/default.min.css"&gt;
179 &lt;script src="http://yandex.st/highlightjs/8.0/highlight.min.js"&gt;&lt;/script&gt;
180 &lt;script&gt; (fuction () { hljs.initHighlightingOnLoad(); })(); &lt;/script&gt;</code></pre>
181  
182 <h2>Tables</h2>
183  
184 <p><em>source</em>:</p>
185  
186 <pre class="hljs"><code class="language-markdown">| Item | Value | Qty |
187 | --------- | -----:|:--: |
188 | Computer | $1600 | 5 |
189 | Phone | $12 | 12 |
190 | Pipe | $1 |234 |</code></pre>
191  
192 <p><em>result</em>:</p>
193  
194 <table class="table table-striped">
195 <thead>
196 <tr>
197 <th>Item</th>
198 <th style="text-align:right;">Value</th>
199 <th style="text-align:center;">Qty</th>
200 </tr>
201 </thead>
202 <tr>
203 <td>Computer</td>
204 <td style="text-align:right;">$1600</td>
205 <td style="text-align:center;">5</td>
206 </tr>
207 <tr>
208 <td>Phone</td>
209 <td style="text-align:right;">$12</td>
210 <td style="text-align:center;">12</td>
211 </tr>
212 <tr>
213 <td>Pipe</td>
214 <td style="text-align:right;">$1</td>
215 <td style="text-align:center;">234</td>
216 </tr>
217 </table>
218  
219  
220 <h2>Fenced Code Blocks</h2>
221  
222 <p><em>source</em>:</p>
223  
224 <pre class="hljs"><code>```perl
225 #!/usr/bin/env perl
226  
227 use strict;
228 use warnings;
229 use Galileo;
230 ```
231 </code></pre>
232  
233 <p><em>result</em>:</p>
234  
235 <pre class="hljs"><code class="language-perl">#!/usr/bin/env perl
236  
237 use strict;
238 use warnings;
239 use Galileo;</code></pre>
240  
241 <h2>Definition Lists</h2>
242  
243 <p><em>source</em>:</p>
244  
245 <pre class="hljs"><code>Term 1
246 : Definition 1
247  
248 Term 2
249 : This definition has a code block.
250  
251 code block</code></pre>
252  
253 <p><em>result</em>:</p>
254  
255 <dl>
256 <dt>Term 1</dt>
257 <dd>Definition 1</dd>
258  
259 <dt>Term 2</dt>
260 <dd>
261 <p>This definition has a code block.</p>
262  
263 <pre class="hljs"><code>code block
264 </code></pre>
265 </dd>
266 </dl>
267  
268 <h2>Special Attributes</h2>
269  
270 <p>You can add class and id attributes to headers and gfm fenced code blocks.</p>
271  
272 <p><em>source</em>:</p>
273  
274 <pre class="hljs"><code>``` {#gfm-id .gfm-class}
275 var foo = bar;
276 ```
277  
278 ## A Header {#header-id}
279  
280 ### Another One ### {#header-id .hclass}
281  
282 Underlined {#what}
283 ==========
284 </code></pre>
285  
286 <p><em>result</em>:</p>
287  
288 <pre class="hljs"><code class="language-html">&lt;pre id="gfm-id" class="gfm-class prettyprint"&gt;&lt;code&gt;var foo = bar;&lt;/code&gt;&lt;/pre&gt;
289  
290 &lt;h2 id="header-id"&gt;A Header&lt;/h2&gt;
291  
292 &lt;h3 id="header-id" class="hclass"&gt;Another One&lt;/h3&gt;
293  
294 &lt;h1 id="what"&gt;Underlined &lt;/h1&gt;</code></pre>
295  
296 <h2>Footnotes</h2>
297  
298 <p><em>source</em>:</p>
299  
300 <pre class="hljs"><code>Here is a footnote which will be located at the end of the page[^footnote].
301  
302 [^footnote]: Here is the *text* of the **footnote**.</code></pre>
303  
304 <p><em>result</em>:</p>
305  
306 <p>Here is a footnote which will be located at the end of the page<a href="#fn:footnote" id="fnref:footnote" title="See footnote" class="footnote">1</a>.</p>
307  
308 <h2>SmartyPants</h2>
309  
310 <p>SmartyPants extension converts ASCII punctuation characters into &#8220;smart&#8221; typographic punctuation HTML entities.</p>
311  
312 <table class="table table-striped">
313 <thead>
314 <tr>
315 <th></th>
316 <th>ASCII</th>
317 <th>HTML</th>
318 </tr>
319 </thead>
320 <tr>
321 <td>Single backticks</td>
322 <td><code>'Isn't this fun?'</code></td>
323 <td>&#8216;Isn&#8217;t this fun?&#8217;</td>
324 </tr>
325 <tr>
326 <td>Quotes</td>
327 <td><code>"Isn't this fun?"</code></td>
328 <td>&#8220;Isn&#8217;t this fun?&#8221;</td>
329 </tr>
330 <tr>
331 <td>Dashes</td>
332 <td><code>This -- is an en-dash and this --- is an em-dash</code></td>
333 <td>This &#8211; is an en-dash and this &#8212; is an em-dash</td>
334 </tr>
335 </table>
336  
337  
338 <h2>Newlines</h2>
339  
340 <p><em>source</em>:</p>
341  
342 <pre class="hljs"><code>Roses are red
343 Violets are blue</code></pre>
344  
345 <p><em>result</em>:</p>
346  
347 <p>Roses are red <br>
348 Violets are blue</p>
349  
350 <h2>Strikethrough</h2>
351  
352 <p><em>source</em>:</p>
353  
354 <pre class="hljs"><code>~~Mistaken text.~~</code></pre>
355  
356 <p><em>result</em>:</p>
357  
358 <p><del>Mistaken text.</del></p>
359  
360 <div class="footnotes">
361 <hr>
362 <ol>
363  
364 <li id="fn:footnote">Here is the <em>text</em> of the <strong>footnote</strong>. <a href="#fnref:footnote" title="Return to article" class="reversefootnote">&#8617;</a></li>
365  
366 </ol>
367 </div>
368 HTML
369 md => <<'MARKDOWN',
370 ## Highlighting
371  
372 Default highlighter is [highlight.js](http://highlightjs.org/). But Galileo just generates HTML so if you want to see colorized output then you have to load javascript and css.
373  
374 ```xml
375 <!-- example -->
376 <link rel="stylesheet" href="http://yandex.st/highlightjs/8.0/styles/default.min.css">
377 <script src="http://yandex.st/highlightjs/8.0/highlight.min.js"></script>
378 <script> (fuction () { hljs.initHighlightingOnLoad(); })(); </script>
379 ```
380  
381 ## Tables
382  
383 *source*:
384  
385 ```markdown
386 | Item | Value | Qty |
387 | --------- | -----:|:--: |
388 | Computer | $1600 | 5 |
389 | Phone | $12 | 12 |
390 | Pipe | $1 |234 |
391 ```
392  
393 *result*:
394  
395 | Item | Value | Qty |
396 | --------- | -----:|:--: |
397 | Computer | $1600 | 5 |
398 | Phone | $12 | 12 |
399 | Pipe | $1 |234 |
400  
401  
402 ## Fenced Code Blocks
403  
404 *source*:
405  
406 ```perl
407 #!/usr/bin/env perl
408  
409 use strict;
410 use warnings;
411 use Galileo;
412 ```
413  
414 *result*:
415  
416 ```perl
417 #!/usr/bin/env perl
418  
419 use strict;
420 use warnings;
421 use Galileo;
422 ```
423  
424 ## Definition Lists
425  
426 *source*:
427  
428 ```
429 Term 1
430 : Definition 1
431  
432 Term 2
433 : This definition has a code block.
434  
435 code block
436 ```
437  
438 *result*:
439  
440 Term 1
441 : Definition 1
442  
443 Term 2
444 : This definition has a code block.
445  
446 code block
447  
448 ## Special Attributes
449  
450 You can add class and id attributes to headers and gfm fenced code blocks.
451  
452 *source*:
453  
454 ``` {#gfm-id .gfm-class}
455 var foo = bar;
456 ```
457  
458 ## A Header {#header-id}
459  
460 ### Another One ### {#header-id .hclass}
461  
462 Underlined {#what}
463 ==========
464  
465 *result*:
466  
467 ```html
468 <pre id="gfm-id" class="gfm-class prettyprint"><code>var foo = bar;</code></pre>
469  
470 <h2 id="header-id">A Header</h2>
471  
472 <h3 id="header-id" class="hclass">Another One</h3>
473  
474 <h1 id="what">Underlined </h1>
475 ```
476  
477 ## Footnotes
478  
479 *source*:
480  
481 ```
482 Here is a footnote which will be located at the end of the page[^footnote].
483  
484 [^footnote]: Here is the *text* of the **footnote**.
485 ```
486  
487 *result*:
488  
489 Here is a footnote which will be located at the end of the page[^footnote].
490  
491 [^footnote]: Here is the *text* of the **footnote**.
492  
493 ## SmartyPants
494  
495 SmartyPants extension converts ASCII punctuation characters into "smart" typographic punctuation HTML entities.
496  
497 | | ASCII | HTML |
498 ------------------|----------------------------------------------------|-------------------------------------
499 | Single backticks | `'Isn't this fun?'` | &#8216;Isn&#8217;t this fun?&#8217; |
500 | Quotes | `"Isn't this fun?"` | &#8220;Isn&#8217;t this fun?&#8221; |
501 | Dashes | `This -- is an en-dash and this --- is an em-dash` | This &#8211; is an en-dash and this &#8212; is an em-dash |
502  
503 ## Newlines
504  
505 *source*:
506  
507 ```
508 Roses are red
509 Violets are blue
510 ```
511  
512 *result*:
513  
514 Roses are red
515 Violets are blue
516  
517 ## Strikethrough
518  
519 *source*:
520  
521 ```
522 ~~Mistaken text.~~
523 ```
524  
525 *result*:
526  
527 ~~Mistaken text.~~
528 MARKDOWN
529 author_id => $admin->user_id,
530 });
531  
532 3 $schema->resultset('Menu')->create({
533 name => 'main',
534 list => j( [ $syntax->page_id, $about->page_id ] ),
535 });
536 }
537  
538 3 ▶sub create_test_object {
Subroutine create_test_object: called CC=4 SCAR=14.0
Pod undocumented
539 3 my $class = shift;
540 3 ▶ my $opts = ref $_[-1] eq 'HASH' ? pop : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'HASH' ? : 3 0 3
541  
542 3 require Galileo;
543 3 require Galileo::DB::Schema;
544  
545 3 my $db = Galileo::DB::Schema->connect('dbi:SQLite:dbname=:memory:','','',{sqlite_unicode=>1});
546  
547 3 my $dh = __PACKAGE__->new(
548 databases => [],
549 schema => $db,
550 );
551 3 $dh->do_install;
552 3 $dh->inject_sample_data('admin', 'pass', 'Joe Admin');
553  
554  
555 3 ▶ if ($opts->{test}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"test"}) 3 0 3
556 3 require Test::More;
557 3 Test::More::ok(
558 $db->resultset('User')->single({name => 'admin'})->check_password('pass'),
559 'DB user checks out'
560 );
561 3 Test::More::ok( $dh->installed_version, 'Found version information' );
562 }
563  
564 3 require Test::Mojo;
565 3 my $t = Test::Mojo->new(Galileo->new(db => $db));
566  
567 3 ▶ return wantarray ? ($t, $dh) : $t;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
568 }
569  
570 3 1;
571  
« Galileo/Page.pm ↑ Summary Galileo/User.pm »