Commit | Line | Data |
9d759b64 |
1 | package DX::Utils; |
2 | |
3 | use strictures 2; |
4 | use Exporter 'import'; |
5 | |
efad53c4 |
6 | my @const = ( |
7 | my @dep_types = qw(EXISTENCE_OF INDICES_OF TYPE_OF CONTENTS_OF), |
8 | my @ev_types = qw(VALUE_SET VALUE_EXISTS), |
9 | ); |
9d759b64 |
10 | |
efad53c4 |
11 | our @EXPORT_OK = ( |
12 | @const, |
1e812b19 |
13 | (my @builders = qw(step string number dict proposition)), |
14 | 'deparse', |
efad53c4 |
15 | ); |
16 | |
17 | our %EXPORT_TAGS = ( |
18 | all => \@EXPORT_OK, |
19 | dep_types => \@dep_types, |
20 | event_types => \@ev_types, |
21 | builders => \@builders, |
22 | ); |
23 | |
24 | require constant; |
25 | |
26 | # use constant INDICES_OF => \*INDICES_OF; |
27 | |
28 | constant->import(+{ |
29 | map {; no strict 'refs'; $_ => \*$_ } @const |
30 | }); |
31 | |
32 | # $INDICES_OF = 1, ... |
33 | |
34 | do { no strict 'refs'; ${$dep_types[$_-1]} = $_ } for 1..@dep_types; |
35 | |
36 | # VALUE_EXISTS needs to trigger indices checks on its parent |
37 | |
38 | our $VALUE_EXISTS = 1; |
39 | |
40 | # VALUE_EXISTS triggers all types, VALUE_SET all but EXISTENCE_OF |
41 | |
42 | our @VALUE_EXISTS = (EXISTENCE_OF(), INDICES_OF(), TYPE_OF(), CONTENTS_OF()); |
43 | our @VALUE_SET = (INDICES_OF(), TYPE_OF(), CONTENTS_OF()); |
9d759b64 |
44 | |
45 | sub step { |
3e465d5d |
46 | require DX::Step::Normal; |
9d759b64 |
47 | DX::Step::Normal->new(@_); |
48 | } |
49 | |
50 | sub string { |
3e465d5d |
51 | require DX::Value::String; |
9d759b64 |
52 | DX::Value::String->new(string_value => $_[0]) |
53 | } |
54 | |
55 | sub number { |
3e465d5d |
56 | require DX::Value::Number; |
9d759b64 |
57 | DX::Value::Number->new(number_value => $_[0]); |
58 | } |
59 | |
efad53c4 |
60 | sub dict { |
3e465d5d |
61 | require DX::Value::Dict; |
efad53c4 |
62 | DX::Value::Dict->new( |
63 | members => { @_ }, |
64 | ); |
65 | } |
66 | |
67 | sub proposition { |
68 | my ($pred, @args) = @_; |
3e465d5d |
69 | require DX::Proposition; |
efad53c4 |
70 | DX::Proposition->new( |
71 | predicate => $pred, |
72 | args => \@args, |
73 | ); |
74 | } |
75 | |
1e812b19 |
76 | { |
3e465d5d |
77 | my $dp; |
1e812b19 |
78 | |
79 | sub deparse { |
3e465d5d |
80 | $dp ||= do { |
81 | require DX::Deparse; |
82 | DX::Deparse->new; |
83 | }; |
1e812b19 |
84 | my ($thing) = @_; |
85 | $dp->fmt($thing); |
86 | } |
87 | } |
88 | |
9d759b64 |
89 | 1; |