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