line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl6ish::Syntax::state; |
2
|
1
|
|
|
1
|
|
1277
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use Scalar::Util qw(refaddr); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
140
|
|
5
|
1
|
|
|
1
|
|
1042
|
use Devel::Caller qw(called_with caller_cv); |
|
1
|
|
|
|
|
3347
|
|
|
1
|
|
|
|
|
63
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
867
|
use Devel::Declare; |
|
1
|
|
|
|
|
5559
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
1802
|
use Data::Bind; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our ($Declarator, $Offset); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub skip_declarator { |
13
|
|
|
|
|
|
|
$Offset += Devel::Declare::toke_move_past_token($Offset); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %stash = (); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub handle_state { |
19
|
|
|
|
|
|
|
my $line = Devel::Declare::get_linestr; |
20
|
|
|
|
|
|
|
$Offset = Devel::Declare::get_linestr_offset; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
if (my ($statement, $sigil, $name, $val) = $line =~ /(\bstate\s+([\$\@\%])(\w+)\s*=\s*(.+);)/) { |
23
|
|
|
|
|
|
|
skip_declarator; |
24
|
|
|
|
|
|
|
my $var = "$sigil$name"; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
substr( $line, $Offset, length($statement) ) = "(my $var, $val);"; |
27
|
|
|
|
|
|
|
Devel::Declare::set_linestr($line); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub state(\$$) { |
32
|
|
|
|
|
|
|
my ($varref, $varval) = @_; |
33
|
|
|
|
|
|
|
my $varname = (called_with(0, 1))[0]; |
34
|
|
|
|
|
|
|
my $caller_addr = refaddr( caller_cv(1) ); |
35
|
|
|
|
|
|
|
my $k = "$caller_addr $varname"; |
36
|
|
|
|
|
|
|
$$varref = $stash{ $k } ||= $varval; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
bind_op2( $varref, \$stash{$k} ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub import { |
42
|
|
|
|
|
|
|
my $caller = caller; |
43
|
|
|
|
|
|
|
no strict; |
44
|
|
|
|
|
|
|
*{"$caller\::state"} = \&state; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Devel::Declare->setup_for( |
47
|
|
|
|
|
|
|
$caller => { state => { const => \&handle_state } } |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |