line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Language::Prolog::Sugar; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
21394
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp qw(carp croak); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
79
|
|
9
|
1
|
|
|
1
|
|
1000
|
use Language::Prolog::Types ':ctors'; |
|
1
|
|
|
|
|
7937
|
|
|
1
|
|
|
|
|
228
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub export { |
13
|
0
|
|
|
0
|
0
|
0
|
my ($sub, $pkg, $name)=@_; |
14
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
852
|
|
15
|
0
|
|
|
|
|
0
|
*{$pkg.'::'.$name}=$sub; |
|
0
|
|
|
|
|
0
|
|
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
19
|
1
|
|
|
1
|
|
9
|
my $class=shift; |
20
|
1
|
50
|
|
|
|
5
|
my $to=caller |
21
|
|
|
|
|
|
|
or die "unable to infer importer package"; |
22
|
1
|
|
|
|
|
12
|
while(@_) { |
23
|
0
|
|
|
|
|
|
my $key=shift; |
24
|
0
|
0
|
0
|
|
|
|
if ($key eq 'vars' or $key eq 'variables') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $vars=shift; |
26
|
0
|
0
|
|
|
|
|
if (ref $vars eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
foreach (@{$vars}) { |
|
0
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $var=prolog_var($_); |
29
|
0
|
|
|
0
|
|
|
export sub () { $var }, $to, $_; |
|
0
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif (ref $vars eq 'HASH') { |
33
|
0
|
|
|
|
|
|
foreach my $name (keys %{$vars}) { |
|
0
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $var=prolog_var($name); |
35
|
0
|
|
|
0
|
|
|
export sub () { $var }, $to, $name; |
|
0
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
0
|
|
|
|
|
|
croak "invalid argument '$vars' for $key option"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
elsif ($key eq 'functors') { |
43
|
0
|
|
|
|
|
|
my $functors=shift; |
44
|
0
|
0
|
|
|
|
|
if (ref $functors eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
foreach (@{$functors}) { |
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $functor=$_; |
47
|
|
|
|
|
|
|
export sub { |
48
|
0
|
|
|
0
|
|
|
prolog_functor($functor, @_); |
49
|
0
|
|
|
|
|
|
}, $to, $functor; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif (ref $functors eq 'HASH') { |
53
|
0
|
|
|
|
|
|
foreach my $name (keys %{$functors}) { |
|
0
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $functor=$functors->{$name}; |
55
|
|
|
|
|
|
|
export sub { |
56
|
0
|
|
|
0
|
|
|
prolog_functor($functor, @_); |
57
|
0
|
|
|
|
|
|
}, $to, $name; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
0
|
|
|
|
|
|
croak "invalid argument '$functors' for $key option"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
elsif ($key eq 'atoms') { |
65
|
0
|
|
|
|
|
|
my $atoms=shift; |
66
|
0
|
0
|
|
|
|
|
if (ref $atoms eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
foreach (@{$atoms}) { |
|
0
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $atom=$_; |
69
|
0
|
|
|
0
|
|
|
export sub () { $atom }, $to, $atom; |
|
0
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif (ref $atoms eq 'HASH') { |
73
|
0
|
|
|
|
|
|
foreach my $name (keys %{$atoms}) { |
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $atom=$atoms->{$name}; |
75
|
0
|
|
|
0
|
|
|
export sub () { $atom }, $to, $name; |
|
0
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
0
|
|
|
|
|
|
croak "invalid argument '$atoms' for $key option"; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
elsif ($key eq 'chains') { |
83
|
0
|
|
|
|
|
|
my $chains=shift; |
84
|
0
|
0
|
|
|
|
|
if (ref $chains eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
foreach (@{$chains}) { |
|
0
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $chain=$_; |
87
|
|
|
|
|
|
|
export sub { |
88
|
0
|
|
|
0
|
|
|
prolog_chain($chain, @_); |
89
|
0
|
|
|
|
|
|
}, $to, $chain; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
elsif (ref $chains eq 'HASH') { |
93
|
0
|
|
|
|
|
|
foreach my $name (keys %{$chains}) { |
|
0
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $chain=$chains->{$name}; |
95
|
|
|
|
|
|
|
export sub { |
96
|
0
|
|
|
0
|
|
|
prolog_chain($chain, @_); |
97
|
0
|
|
|
|
|
|
}, $to, $name; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
0
|
|
|
|
|
|
croak "invalid argument '$chains' for $key option"; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
elsif ($key eq 'auto_functor') { |
105
|
0
|
|
|
|
|
|
carp "Language::Prolog::Sugar auto_functor has been obsoleted"; |
106
|
0
|
|
|
|
|
|
export \&_auto_functor, $to, 'AUTOLOAD'; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
elsif ($key eq 'auto_term') { |
109
|
0
|
|
|
|
|
|
export \&_auto_term, $to, 'AUTOLOAD'; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
0
|
|
|
|
|
|
croak "Unknow option '$key'"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
our $AUTOLOAD; |
118
|
|
|
|
|
|
|
sub _auto_functor { |
119
|
0
|
|
|
0
|
|
|
my ($pkg, $name) = $AUTOLOAD =~ /(?:(.*)::)?(.*)/; |
120
|
0
|
0
|
|
|
|
|
$pkg = 'main' unless length $pkg; |
121
|
0
|
0
|
|
|
|
|
$name =~ /^[A-Z]/ |
122
|
|
|
|
|
|
|
and croak "invalid functor name '$name': starts with uppercase"; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
0
|
|
|
export sub { prolog_functor($name, @_) }, $pkg, $name; |
|
0
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
213
|
|
127
|
0
|
|
|
|
|
|
goto &$AUTOLOAD |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _auto_term { |
131
|
0
|
|
|
0
|
|
|
my ($pkg, $name) = $AUTOLOAD =~ /(?:(.*)::)?(.*)/; |
132
|
0
|
0
|
|
|
|
|
$pkg = 'main' unless length $pkg; |
133
|
0
|
0
|
|
|
|
|
if ($name =~ /^[A-Z]/) { |
134
|
0
|
|
|
|
|
|
my $var = prolog_var $name; |
135
|
0
|
|
|
0
|
|
|
my $sub = sub () { $var }; |
|
0
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
export $sub, $pkg, $name; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else { |
139
|
0
|
|
|
0
|
|
|
export sub { prolog_functor($name, @_) }, $pkg, $name; |
|
0
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
143
|
0
|
|
|
|
|
|
goto &$AUTOLOAD |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
__END__ |