blib/lib/Dallycot/Library/CLI.pm

filter: Statementstmt 37.3% 28 / 75 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 43.7% 7 / 16 Podpod n/a totaltotal 31.2% 35 / 112 CC 10 SCAR 20.3
CC
10
Cov
30%
__ANON__
20.0
__ANON__
12.0
__ANON__
12.0
CRAP 7.6
« blib/lib/Dallycot/Channel/Terminal.pm ↑ Summary blib/lib/Dallycot/Processor.pm »
1 package Dallycot::Library::CLI;
2 9 our $AUTHORITY = 'cpan:JSMITH';
3  
4 # ABSTRACT: functions for use with the command line interface
5  
6 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Dallycot::Library;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 9 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Promises qw(deferred collect);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 9 ▶use experimental qw(switch);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 9 ns 'http://www.dallycot.net/ns/cli/1.0#';
18  
19 define
20 print => (
21 hold => 0,
22 arity => [1],
23 options => {}
24 ),
25 sub {
26 0 ▶ my ( $engine, $options, @things ) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
27  
28 0 my $d = deferred;
29  
30 0 for my $thing (@things) {
31 0 ▶ if ( $thing->isa('Dallycot::Value::String') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->isa('Dallycot::Value::String')) { } 0 0 0
32 0 $engine->channel_send( '$OUTPUT', $thing->value );
33 }
34 else {
35 0 $engine->channel_send( '$OUTPUT', $thing->as_text );
36 }
37 }
38 0 $engine->channel_send( '$OUTPUT', "\n" );
39 0 $d->resolve( $engine->TRUE );
40 0 return $d->promise;
41 9 };
42  
43 define emit => (
44 hold => 0,
45 arity => 1,
46 options => {}
47 ), sub {
48 0 ▶ my ( $engine, $options, $point ) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
49  
50 0 ▶ if(!$point || !$point->isa('Dallycot::Value::Numeric') || !$point->value->is_int) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($point and $point->isa("Dallycot::Value::Numeric") and $point->value->is_int) 0 0 0
Condition0%0/6
$point and $point->isa("Dallycot::Value::Numeric") and $point->value->is_int
!ll&&!rl&&r
000
$point and $point->isa("Dallycot::Value::Numeric")
!ll&&!rl&&r
000
MC/DC0%0/3
$point and $point->isa("Dallycot::Value::Numeric") and $point->value->is_int
$point $point->isa("Dallycot::Value::Numeric") $point->value->is_int
Truth table0%0/4
A and B and C
A= $pointB= $point->isa("Dallycot::Value::Numeric")C= $point->value->is_int
ABCresult
0XX0
10X0
1100
1111
51 0 croak 'emit requires an integer code point';
52 }
53  
54 0 $engine->channel_send( '$OUTPUT', chr($point->value->numify));
55 0 my $d = deferred;
56 0 $d -> resolve($engine -> TRUE);
57 0 return $d -> promise;
58 9 };
59  
60 define
61 'input-string' => (
62 hold => 0,
63 arity => [ 0, 1 ],
64 options => {}
65 ),
66 sub {
67 0 ▶ my ( $engine, $options, $prompt ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
68  
69 0 my %options;
70 0 ▶ if ($prompt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prompt) 0 0 0
71 0 $options{prompt} = $prompt;
72 }
73  
74 0 return $engine->channel_read( '$INPUT', %options );
75 9 };
76  
77 define
78 input => (
79 hold => 0,
80 arity => [ 0, 1 ],
81 options => {}
82 ),
83 sub {
84 0 ▶ my ( $engine, $options, $prompt ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
85  
86 0 my %options;
87 0 ▶ if ($prompt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prompt) 0 0 0
88 0 $options{prompt} = $prompt;
89 }
90  
91 0 my $d = deferred;
92 0 _get_valid_input( $engine, $d, '$INPUT', %options );
93 0 return $d->promise;
94 9 };
95  
96 sub _get_valid_input {
97 0 ▶ my ( $engine, $d, $channel, %options ) = @_;
Subroutine _get_valid_input: not called CC=1 SCAR=6.9
98  
99 $engine->channel_read( $channel, %options )->done(
100 sub {
101 0 ▶ my ($string) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
102 0 my $source = $string->value;
103 0 my $parser = Dallycot::Parser->new;
104 0 my $parse = $parser->parse($source);
105 0 ▶ if ($parse) {
Branch: 2 branches
BranchTrueFalseTotal
if ($parse) { } 0 0 0
elsif ($parser->error) { } 0 0 0
106 $engine->new->execute(@$parse)->done(
107 sub {
108 0 ▶ $d->resolve(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
109 },
110 sub {
111 0 ▶ my ($err) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
112 0 $engine->channel_send( '$OUTPUT', "*** $err\n" );
113 0 _get_valid_input( $engine, $d, $channel, %options );
114 }
115 0 );
116 }
117 elsif ( $parser->error ) {
118 0 $engine->channel_send( '$OUTPUT', "*** " . $parser->error . "\n" );
119 0 _get_valid_input( $engine, $d, $channel, %options );
120 }
121 else {
122 0 _get_valid_input( $engine, $d, $channel, %options );
123 }
124 },
125 sub {
126 0 ▶ my ($err) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
127 0 $engine->channel_send( '$OUTPUT', "*** $err\n" );
128 0 _get_valid_input( $engine, $d, $channel, %options );
129 }
130 0 );
131 0 return;
132 }
133  
134 9 1;
« blib/lib/Dallycot/Channel/Terminal.pm ↑ Summary blib/lib/Dallycot/Processor.pm »