File Coverage

blib/lib/Dallycot/AST/Invert.pm
Criterion Covered Total %
statement 12 24 50.0
branch 0 4 0.0
condition 0 3 0.0
subroutine 4 8 50.0
pod 0 3 0.0
total 16 42 38.1


line stmt bran cond sub pod time code
1             package Dallycot::AST::Invert;
2             our $AUTHORITY = 'cpan:JSMITH';
3              
4             # ABSTRACT: Invert the truth of an expression or value
5              
6 23     23   12157 use strict;
  23         37  
  23         740  
7 23     23   94 use warnings;
  23         24  
  23         455  
8              
9 23     23   84 use utf8;
  23         31  
  23         101  
10 23     23   406 use parent 'Dallycot::AST';
  23         38  
  23         97  
11              
12             sub new {
13 0     0 0   my ( $class, $expr ) = @_;
14              
15 0   0       $class = ref $class || $class;
16 0           return bless [$expr] => $class;
17             }
18              
19              
20             sub to_rdf {
21 0     0 0   my($self, $model) = @_;
22              
23 0           return $model -> apply(
24             $model -> meta_uri('loc:invert'),
25             [ $self->[0] ],
26             {}
27             );
28             }
29              
30             sub execute {
31 0     0 0   my ( $self, $engine ) = @_;
32              
33             return $engine->execute( $self->[0] )->then(
34             sub {
35 0     0     my ($res) = @_;
36              
37 0 0         if ( $res->isa('Dallycot::Value::Boolean') ) {
    0          
38 0           return Dallycot::Value::Boolean->new( !$res->value );
39             }
40             elsif ( $res->isa('Dallycot::Value::Lambda') ) {
41 0           return Dallycot::Value::Lambda->new(
42             expression => Dallycot::AST::Invert->new( $res->[0] ),
43             bindings => $res->[1],
44             bindings_with_defaults => $res->[2],
45             options => $res->[3],
46             closure_environment => $res->[4],
47             closure_namespaces => $res->[5]
48             );
49             }
50             else {
51 0           return Dallycot::Value::Boolean->new( !$res->is_defined );
52             }
53             }
54 0           );
55             }
56              
57             1;