line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2003 Ioannis Tambouras . |
2
|
|
|
|
|
|
|
# All rights reserved. |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package String::RexxStack::Named; |
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
264065
|
use 5.006; |
|
8
|
|
|
|
|
30
|
|
|
8
|
|
|
|
|
327
|
|
7
|
8
|
|
|
8
|
|
46
|
use strict; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
339
|
|
8
|
8
|
|
|
8
|
|
58
|
use warnings; |
|
8
|
|
|
|
|
36
|
|
|
8
|
|
|
|
|
318
|
|
9
|
8
|
|
|
8
|
|
50
|
use base qw( Exporter String::TieStack ); |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
6706
|
|
10
|
|
|
|
|
|
|
use Filter::Simple; |
11
|
|
|
|
|
|
|
use Want qw(wantref want); |
12
|
|
|
|
|
|
|
use Data::Dumper; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.3'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT = qw( pull Pull Push Pop clear qelem Queue ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @extra = qw( newstack printq printq_s info |
19
|
|
|
|
|
|
|
qstack delstack dumpe dumpe_s |
20
|
|
|
|
|
|
|
limits limit_bytes limit_entries |
21
|
|
|
|
|
|
|
makebuf dropbuf desbuf qbuf |
22
|
|
|
|
|
|
|
total_bytes ) ; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'extra' => [ @extra ], |
25
|
|
|
|
|
|
|
'all' => [ @EXPORT, @extra ], |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'extra'} } ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
FILTER { |
34
|
|
|
|
|
|
|
my $tmp; |
35
|
|
|
|
|
|
|
my $pat = qr! \[ \s* (makebuf | dropbuf | desbuf | clear | |
36
|
|
|
|
|
|
|
newstack | delstack | qstack | |
37
|
|
|
|
|
|
|
printq | printq_s | dumpe |
38
|
|
|
|
|
|
|
) |
39
|
|
|
|
|
|
|
\s* (\S*) \s* \] !ix; |
40
|
|
|
|
|
|
|
s ! $pat \s* (;?) |
41
|
|
|
|
|
|
|
! $tmp = lc "$1" ; |
42
|
|
|
|
|
|
|
$tmp = "$tmp $2" ; |
43
|
|
|
|
|
|
|
$tmp .= ';' if $3 ; |
44
|
|
|
|
|
|
|
$tmp; |
45
|
|
|
|
|
|
|
!exg; |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my %DEFAULT = ( Max_SoStacks => 10, Max_Named=> 20 ); # NOT USED |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _create_entry { { stack => new String::TieStack, |
54
|
|
|
|
|
|
|
max_sos => $DEFAULT{ Max_SoStacks }, |
55
|
|
|
|
|
|
|
saved => [] , |
56
|
|
|
|
|
|
|
} ; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my %s = ( SESSION => _create_entry ); |
60
|
|
|
|
|
|
|
my $max_named = $DEFAULT{ max_named } ; |
61
|
|
|
|
|
|
|
my $num_named = 1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub qstack { return 0 unless $s{my $name = shift||'SESSION'} ; |
65
|
|
|
|
|
|
|
1 + scalar @{ $s{$name}{saved} } ; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub Pull { $s{ defined $_[1] ? shift :'SESSION' } {stack}->pull(@_) } |
69
|
|
|
|
|
|
|
sub pull { ($s{ shift || 'SESSION' }{stack} || return undef) ->pullall } |
70
|
|
|
|
|
|
|
sub qelem { ($s{ shift || 'SESSION' }{stack} || return undef) ->qelem } |
71
|
|
|
|
|
|
|
sub qbuf { ($s{ shift || 'SESSION' }{stack} || return undef) ->qbuf } |
72
|
|
|
|
|
|
|
sub clear { ($s{ shift || 'SESSION' }{stack} || return undef) ->CLEAR } |
73
|
|
|
|
|
|
|
sub makebuf { ($s{ shift || 'SESSION' }{stack} || return undef) ->makebuf } |
74
|
|
|
|
|
|
|
sub dropbuf { ($s{ shift || 'SESSION' }{stack} || return undef) ->dropbuf } |
75
|
|
|
|
|
|
|
sub desbuf { ($s{ shift || 'SESSION' }{stack} || return undef) ->desbuf } |
76
|
|
|
|
|
|
|
sub printq { $,="\n"; print +($s{ shift||'SESSION'} {stack}|| return undef) ->printq } |
77
|
|
|
|
|
|
|
sub printq_s { $,="\n"; +($s{ shift||'SESSION'} {stack}|| return undef) ->printq } |
78
|
|
|
|
|
|
|
sub total_bytes { ($s{ shift || 'SESSION' }{stack} || return undef) ->total_bytes } |
79
|
|
|
|
|
|
|
*queue = \&Queue ; |
80
|
|
|
|
|
|
|
*Pop = \& Pull ; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _allow_stack { |
84
|
|
|
|
|
|
|
my $name = shift; |
85
|
|
|
|
|
|
|
qstack($name) + 1 <= $s{$name}{max_sos} ; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub newstack { |
90
|
|
|
|
|
|
|
my $name = shift|| 'SESSION'; |
91
|
|
|
|
|
|
|
if ( exists $s{$name}{stack} ) { |
92
|
|
|
|
|
|
|
return undef unless _allow_stack $name ; |
93
|
|
|
|
|
|
|
my ($entries, $bytes) = $s{$name}{stack}->limits; |
94
|
|
|
|
|
|
|
push @ { $s{$name}{saved} } , $s{$name}{stack}; |
95
|
|
|
|
|
|
|
$s{$name}{stack} = new String::TieStack; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$s{$name}{stack}->{'max_entries'} = $entries; |
98
|
|
|
|
|
|
|
$s{$name}{stack}->{'max_KBytes'} = $bytes ; |
99
|
|
|
|
|
|
|
}else{ |
100
|
|
|
|
|
|
|
$s{ $name } = _create_entry ; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
return qstack $name if want('SCALAR', '!HASH') ; |
103
|
|
|
|
|
|
|
return $s{$name} if want('HASH'); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub delstack { |
108
|
|
|
|
|
|
|
my $name = shift || 'SESSION' ; |
109
|
|
|
|
|
|
|
@{ $s{$name}{saved} } ? do{ $s{$name}{stack} = pop @{ $s{$name}{saved} } } |
110
|
|
|
|
|
|
|
: $s{$name}{stack}->CLEAR ; |
111
|
|
|
|
|
|
|
qstack $name ; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
sub Queue { |
114
|
|
|
|
|
|
|
my $name = defined $_[1] ? shift :'SESSION' ; |
115
|
|
|
|
|
|
|
newstack $name unless $s{$name} ; |
116
|
|
|
|
|
|
|
$s{ $name } {stack}->queue(@_) |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub dumpe { |
120
|
|
|
|
|
|
|
my $name = shift || 'SESSION' ; |
121
|
|
|
|
|
|
|
print Data::Dumper->Dump( [$s{$name}] , ["*$name"] ) |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub Push ($;@) { |
125
|
|
|
|
|
|
|
my $name = $_[1] ? shift() : 'SESSION'; |
126
|
|
|
|
|
|
|
newstack $name unless exists $s{$name}{stack} ; |
127
|
|
|
|
|
|
|
$s{ $name }{stack}->PUSH(@_) |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub dumpe_s { |
132
|
|
|
|
|
|
|
my $name = shift || 'SESSION' ; |
133
|
|
|
|
|
|
|
Data::Dumper->Dump( [$s{$name}] , ["*$name"] ) |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub limit_bytes { |
138
|
|
|
|
|
|
|
my ($name, $val) = @_ ; |
139
|
|
|
|
|
|
|
(defined $val) ? ( ($s{$name}->{stack}||newstack($name)->{stack}) ->max_KBytes($val)) |
140
|
|
|
|
|
|
|
: $s{$name || 'SESSION'} {stack} ->max_KBytes() ; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub limit_entries { |
144
|
|
|
|
|
|
|
my ($name, $val) = @_ ; |
145
|
|
|
|
|
|
|
(defined $val) ? ( ($s{$name}->{stack}||newstack($name)->{stack}) ->max_entries($val)) |
146
|
|
|
|
|
|
|
: $s{$name||'SESSION'}{stack} ->max_entries() ; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub limits { |
151
|
|
|
|
|
|
|
my ($q, $ent, $byt ) = @_ ; |
152
|
|
|
|
|
|
|
#$s{$q}{stack} || newstack $q ; |
153
|
|
|
|
|
|
|
(defined $_[1]) ? (limit_entries( $q, $ent ) , limit_bytes( $q, $byt) ) |
154
|
|
|
|
|
|
|
: (limit_entries( $q||'SESSION'), limit_bytes $q||'SESSION') ; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub info { |
158
|
|
|
|
|
|
|
map { |
159
|
|
|
|
|
|
|
(limit_bytes $_) ? sprintf "%-15s %5d stacks %5d entries %9d bytes\n", |
160
|
|
|
|
|
|
|
$_, qstack( $_), qelem( $_) , total_bytes($_) |
161
|
|
|
|
|
|
|
: sprintf "%-15s %5d stacks %5d entries\n", |
162
|
|
|
|
|
|
|
$_, qstack( $_), qelem( $_) ; |
163
|
|
|
|
|
|
|
} keys %s ; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1; |
168
|
|
|
|
|
|
|
__END__ |