line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Find::Scalar; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Find scalar names in a text. |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
226423
|
use 5.006001; |
|
4
|
|
|
|
|
47
|
|
6
|
4
|
|
|
4
|
|
16
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
68
|
|
7
|
4
|
|
|
4
|
|
15
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
2328
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
4
|
|
|
4
|
1
|
1141
|
my ($class) = @_; |
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
|
|
8
|
my $self = {}; |
15
|
4
|
|
|
|
|
8
|
bless $self,$class; |
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
|
|
16
|
$self->_counter(0); |
18
|
|
|
|
|
|
|
|
19
|
4
|
|
|
|
|
10
|
return $self; |
20
|
|
|
|
|
|
|
}# new |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub find { |
23
|
7
|
|
|
7
|
1
|
1120
|
my ($self,$text) = @_; |
24
|
7
|
|
|
|
|
15
|
my @array = (); |
25
|
|
|
|
|
|
|
|
26
|
7
|
|
|
|
|
16
|
$self->_counter(0); |
27
|
|
|
|
|
|
|
|
28
|
7
|
100
|
|
|
|
27
|
return if !defined $text; |
29
|
6
|
100
|
|
|
|
18
|
return if ref $text; |
30
|
|
|
|
|
|
|
|
31
|
5
|
|
|
|
|
35
|
$text =~ s,<<'(.*?)'.*?\n\1,,sg; |
32
|
5
|
|
|
|
|
28
|
$text =~ s,'.*?',,sg; |
33
|
5
|
|
|
|
|
19
|
$text =~ s,q~.*?~,,sg; |
34
|
|
|
|
|
|
|
|
35
|
5
|
|
|
|
|
172
|
@array = $text =~ m/(?:(\$\w+(?:->)?(?:\[\$?\w+\]|\{\$?\w+\}))|(\$\{\w+\})|(\$\w+))/sg; |
36
|
5
|
|
|
|
|
16
|
@array = grep{defined}@array; |
|
162
|
|
|
|
|
207
|
|
37
|
|
|
|
|
|
|
|
38
|
5
|
|
|
|
|
18
|
$self->_elements(@array); |
39
|
|
|
|
|
|
|
|
40
|
5
|
100
|
|
|
|
18
|
return wantarray ? @{$self->_elements()} : $self->_elements(); |
|
1
|
|
|
|
|
2
|
|
41
|
|
|
|
|
|
|
}# find |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub unique { |
44
|
1
|
|
|
1
|
1
|
5
|
my ($self) = @_; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
2
|
my %seen; |
47
|
1
|
|
|
|
|
12
|
my @unique = grep{!$seen{$_}++}@{$self->_elements()}; |
|
13
|
|
|
|
|
28
|
|
|
1
|
|
|
|
|
3
|
|
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
4
|
return \@unique; |
50
|
|
|
|
|
|
|
}# unique |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub count { |
53
|
4
|
|
|
4
|
1
|
11
|
my ($self, $name) = @_; |
54
|
|
|
|
|
|
|
|
55
|
4
|
100
|
|
|
|
10
|
return if !defined $name; |
56
|
3
|
100
|
|
|
|
22
|
return if $name !~ m{\A\$}; |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
3
|
my %counter; |
59
|
2
|
|
|
|
|
3
|
$counter{$_}++ for @{ $self->_elements }; |
|
2
|
|
|
|
|
4
|
|
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
13
|
return $counter{$name}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub hasNext{ |
65
|
14
|
|
|
14
|
1
|
1398
|
my ($self) = @_; |
66
|
|
|
|
|
|
|
|
67
|
14
|
|
|
|
|
15
|
my $count = $self->_counter(); |
68
|
|
|
|
|
|
|
|
69
|
14
|
100
|
|
|
|
16
|
return 0 if $count > $#{ $self->_elements }; |
|
14
|
|
|
|
|
17
|
|
70
|
13
|
|
|
|
|
18
|
return 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub nextElement{ |
74
|
14
|
|
|
14
|
1
|
35
|
my ($self) = @_; |
75
|
|
|
|
|
|
|
|
76
|
14
|
|
|
|
|
16
|
my $count = $self->_counter(); |
77
|
14
|
|
|
|
|
31
|
my $all = $self->_elements(); |
78
|
|
|
|
|
|
|
|
79
|
14
|
|
|
|
|
16
|
my $element = undef; |
80
|
|
|
|
|
|
|
|
81
|
14
|
100
|
|
|
|
25
|
if( $count < scalar @$all ) { |
82
|
13
|
|
|
|
|
23
|
$element = $all->[$count]; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
14
|
|
|
|
|
26
|
$self->_counter(++$count); |
86
|
|
|
|
|
|
|
|
87
|
14
|
|
|
|
|
21
|
return $element; |
88
|
|
|
|
|
|
|
}# nextElement |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _counter{ |
91
|
54
|
|
|
54
|
|
75
|
my ($self,$count) = @_; |
92
|
|
|
|
|
|
|
|
93
|
54
|
100
|
|
|
|
112
|
$self->{Counter} = $count if defined $count; |
94
|
|
|
|
|
|
|
|
95
|
54
|
|
|
|
|
66
|
return $self->{Counter}; |
96
|
|
|
|
|
|
|
}# _Counter |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _elements{ |
99
|
41
|
|
|
41
|
|
57
|
my ($self,@elements) = @_; |
100
|
|
|
|
|
|
|
|
101
|
41
|
100
|
|
|
|
75
|
$self->{Elements} = [@elements] if scalar @elements > 0; |
102
|
|
|
|
|
|
|
|
103
|
41
|
|
|
|
|
90
|
return $self->{Elements}; |
104
|
|
|
|
|
|
|
}# _Elements |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__END__ |