| 1 | #!/usr/bin/env perl | ||||||||||
| 2 | |||||||||||
| 3 | # Copyright (c) 2015-2019 Christian Jaeger, copying@christianjaeger.ch | ||||||||||
| 4 | # This is free software. See the file COPYING.md that came bundled | ||||||||||
| 5 | # with this file. | ||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | # find modules from functional-perl working directory (not installed) | ||||||||||
| 12 | 1 | ▶ | use Cwd 'abs_path'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | our ($mydir, $myname); | |||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.7
| |||||||||||
| 16 | 1 | ▶ | my $location = (-l $0) ? abs_path($0) : $0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 1 | ▶ | $location =~ /(.*?)([^\/]+?)_?\z/s or die "?"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 1 | ($mydir, $myname) = ($1, $2); | |||||||||
| 19 | } | ||||||||||
| 20 | 1 | ▶ | use lib "$mydir/../lib"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | use Chj::TEST | ||||||||||
| 23 | 1 | ▶ | use => "DBD::CSV", | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 1 | use => "FP::DBI"; # 'DBI' really, indirectly | |||||||||
| 25 | 1 | ▶ | use PXML::XHTML ":all"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 1 | ▶ | use FP::Weak; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 1 | ▶ | use Chj::Backtrace; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | |||||||||||
| 30 | 1 | our $db = FP::DBI->connect("dbi:CSV:"); | |||||||||
| 31 | |||||||||||
| 32 | 1 | $db->{csv_sep_char} = ";"; | |||||||||
| 33 | |||||||||||
| 34 | 1 | our $get = $db->prepare("select * from examples/csv_to_xml-example.csv"); | |||||||||
| 35 | |||||||||||
| 36 | 1 | ▶ | TEST { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
| |||||||||||
| 37 | 1 | $get->execute(); | |||||||||
| 38 | 1 | my $s = $get->row_stream; | |||||||||
| 39 | TABLE(TH($s->first->map (\&TD)), | ||||||||||
| 40 | 0 | ▶ | $s->rest->take(10)->map (sub { TR($_[0]->map (\&TD)) }))->string; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 41 | } | ||||||||||
| 42 | 1 | '<table><th><td>1</td><td>2</td><td>3</td><td>4</td></th>' | |||||||||
| 43 | . '<tr><td>4</td><td>3.3</td><td>foo</td><td>bar</td></tr></table>'; | ||||||||||
| 44 | |||||||||||
| 45 | 1 | ▶ | TEST { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 1 | $get->execute(); | |||||||||
| 47 | 1 | my $s = $get->hash_stream; | |||||||||
| 48 | 1 | [Keep($s)->length, $s->second] | |||||||||
| 49 | } | ||||||||||
| 50 | 1 | [2, { a => 4, b => 3.3, c => "foo", d => "bar" }]; | |||||||||
| 51 | |||||||||||
| 52 | # interlock tests: | ||||||||||
| 53 | |||||||||||
| 54 | 1 | ▶ | TEST { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 1 | $get->execute; | |||||||||
| 56 | 1 | my $s = $get->array_stream; | |||||||||
| 57 | 1 | $s->first | |||||||||
| 58 | } | ||||||||||
| 59 | 1 | [1, 2, 3, 4]; | |||||||||
| 60 | |||||||||||
| 61 | 1 | ▶ | TEST_EXCEPTION { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 62 | 1 | $get->execute; | |||||||||
| 63 | 1 | my $s = $get->array_stream; | |||||||||
| 64 | 1 | $get->execute; | |||||||||
| 65 | 1 | $s->first | |||||||||
| 66 | } | ||||||||||
| 67 | 1 | "stream was interrupted by another execute or stream request"; | |||||||||
| 68 | |||||||||||
| 69 | 1 | ▶ | TEST_EXCEPTION { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 70 | 1 | $get->execute; | |||||||||
| 71 | 1 | my $s = $get->array_stream; | |||||||||
| 72 | 1 | my $s2 = $get->hash_stream; | |||||||||
| 73 | 1 | $s->first | |||||||||
| 74 | } | ||||||||||
| 75 | 1 | "stream was interrupted by another execute or stream request"; | |||||||||
| 76 | |||||||||||
| 77 | # XX leak tests? | ||||||||||
| 78 | |||||||||||
| 79 | 1 | ▶ | perhaps_run_tests __PACKAGE__ or do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 0 | require FP::Repl; | |||||||||
| 81 | 0 | FP::Repl::repl(); | |||||||||
| 82 | } | ||||||||||