line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perinci::Sub::PropertyUtil; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2015-12-23'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.09'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
699
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
343
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
declare_property |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub declare_property { |
17
|
0
|
|
|
0
|
1
|
|
my %args = @_; |
18
|
0
|
0
|
|
|
|
|
my $name = $args{name} or die "Please specify property's name"; |
19
|
0
|
0
|
|
|
|
|
my $schema = $args{schema} or die "Please specify property's schema"; |
20
|
0
|
|
|
|
|
|
my $type = $args{type}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
$name =~ m!\A((result|args/\*)/)?\w+\z! or die "Invalid property name"; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# insert the property's schema into Sah::Schema::Rinci |
25
|
|
|
|
|
|
|
{ |
26
|
0
|
|
|
|
|
|
require Sah::Schema::Rinci; |
|
0
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $p = $Sah::Schema::Rinci::SCHEMAS{rinci_function}[1]{_prop} |
28
|
0
|
0
|
|
|
|
|
or die "BUG: Schema structure changed (1)"; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $n; |
31
|
0
|
0
|
|
|
|
|
if ($name =~ m!\Aresult/(.+)!) { |
|
|
0
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$n = $1; |
33
|
|
|
|
|
|
|
$p = $p->{result}{_prop} |
34
|
0
|
0
|
|
|
|
|
or die "BUG: Schema structure changed (2)"; |
35
|
|
|
|
|
|
|
} elsif ($name =~ m!\Aargs/\*/(.+)!) { |
36
|
0
|
|
|
|
|
|
$n = $1; |
37
|
|
|
|
|
|
|
$p = $p->{args}{_value_prop} |
38
|
0
|
0
|
|
|
|
|
or die "BUG: Schema structure changed (3)"; |
39
|
|
|
|
|
|
|
} else { |
40
|
0
|
|
|
|
|
|
$n = $name; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
$p->{$n} |
44
|
|
|
|
|
|
|
and die "Property '$name' is already declared in schema"; |
45
|
|
|
|
|
|
|
# XXX we haven't injected $schema |
46
|
0
|
|
|
|
|
|
$p->{$n} = {}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# install wrapper handler |
50
|
0
|
0
|
|
|
|
|
if ($args{wrapper}) { |
51
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
52
|
1
|
|
|
1
|
|
5
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
128
|
|
53
|
0
|
|
|
|
|
|
my $n = $name; $n =~ s!(/\*)?/!__!g; |
|
0
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
*{"Perinci::Sub::Wrapper::handlemeta_$n"} = |
55
|
0
|
|
|
0
|
|
|
sub { $args{wrapper}{meta} }; |
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
*{"Perinci::Sub::Wrapper::handle_$n"} = |
57
|
0
|
|
|
|
|
|
$args{wrapper}{handler}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# install Perinci::CmdLine help handler |
61
|
0
|
0
|
|
|
|
|
if ($args{cmdline_help}) { |
62
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
63
|
1
|
|
|
1
|
|
4
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
125
|
|
64
|
0
|
|
|
|
|
|
my $n = $name; $n =~ s!/!__!g; |
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
*{"Perinci::CmdLine::help_hookmeta_$n"} = |
66
|
0
|
|
|
0
|
|
|
sub { $args{cmdline_help}{meta} }; |
|
0
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
*{"Perinci::CmdLine::help_hook_$n"} = |
68
|
0
|
|
|
|
|
|
$args{cmdline_help}{handler}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# install Perinci::Sub::To::POD help hook |
72
|
0
|
0
|
|
|
|
|
if ($args{pod}) { |
73
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
74
|
1
|
|
|
1
|
|
6
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
184
|
|
75
|
0
|
|
|
|
|
|
my $n = $name; $n =~ s!/!__!g; |
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
*{"Perinci::Sub::To::POD::hookmeta_$n"} = |
77
|
0
|
|
|
0
|
|
|
sub { $args{pod}{meta} }; |
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
*{"Perinci::Sub::To::POD::hook_$n"} = |
79
|
0
|
|
|
|
|
|
$args{pod}{handler}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
# ABSTRACT: Utility routines for Perinci::Sub::Property::* modules |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |