line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# App::hopen::Util::String - string utilities for hopen |
2
|
|
|
|
|
|
|
package App::hopen::Util::String; |
3
|
2
|
|
|
2
|
|
15
|
use Data::Hopen; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
122
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; use warnings; |
|
2
|
|
|
2
|
|
4
|
|
|
2
|
|
|
|
|
37
|
|
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
46
|
|
5
|
2
|
|
|
2
|
|
10
|
use Data::Hopen::Base; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.000012'; # TRIAL |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
2680
|
use parent 'Exporter'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
16
|
|
10
|
2
|
|
|
2
|
|
1057
|
use vars::i '@EXPORT_OK' => qw(eval_here line_mark_string); |
|
2
|
|
|
|
|
1681
|
|
|
2
|
|
|
|
|
12
|
|
11
|
2
|
|
|
2
|
|
203
|
use vars::i '%EXPORT_TAGS' => (all => [@EXPORT_OK]); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
8
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Docs {{{1 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
App::hopen::Util::String - string utilities for hopen |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
A collection of miscellaneous string utilities. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 FUNCTIONS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# }}}1 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 line_mark_string |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Add a C<#line> directive to a string. Usage: |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $str = line_mark_string <<EOT ; |
34
|
|
|
|
|
|
|
$contents |
35
|
|
|
|
|
|
|
EOT |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
or |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $str = line_mark_string __FILE__, __LINE__, <<EOT ; |
40
|
|
|
|
|
|
|
$contents |
41
|
|
|
|
|
|
|
EOT |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
In the first form, information from C<caller> will be used for the filename |
44
|
|
|
|
|
|
|
and line number. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
The C<#line> directive will point to the line after the C<line_mark_string> |
47
|
|
|
|
|
|
|
invocation, i.e., the first line of <C$contents>. Generally, C<$contents> will |
48
|
|
|
|
|
|
|
be source code, although this is not required. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
C<$contents> must be defined, but can be empty. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub line_mark_string { |
55
|
22
|
|
|
22
|
1
|
143
|
my ($contents, $filename, $line); |
56
|
22
|
50
|
|
|
|
45
|
if(@_ == 1) { |
|
|
0
|
|
|
|
|
|
57
|
22
|
|
|
|
|
34
|
$contents = $_[0]; |
58
|
22
|
|
|
|
|
65
|
(undef, $filename, $line) = caller; |
59
|
|
|
|
|
|
|
} elsif(@_ == 3) { |
60
|
0
|
|
|
|
|
0
|
($filename, $line, $contents) = @_; |
61
|
|
|
|
|
|
|
} else { |
62
|
0
|
|
|
|
|
0
|
croak "Invalid invocation"; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
22
|
50
|
|
|
|
50
|
croak "Need text" unless defined $contents; |
66
|
22
|
50
|
33
|
|
|
71
|
die "Couldn't get location information" unless $filename && $line; |
67
|
|
|
|
|
|
|
|
68
|
22
|
|
|
|
|
40
|
$filename =~ s/"/-/g; |
69
|
22
|
|
|
|
|
30
|
++$line; |
70
|
|
|
|
|
|
|
|
71
|
22
|
|
|
|
|
108
|
return <<EOT; |
72
|
|
|
|
|
|
|
#line $line "$filename" |
73
|
|
|
|
|
|
|
$contents |
74
|
|
|
|
|
|
|
EOT |
75
|
|
|
|
|
|
|
} #line_mark_string() |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 eval_here |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
C<eval> a string, but first, add a C<#line> directive. Usage: |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
eval_here <<EOT |
82
|
|
|
|
|
|
|
$code_to_run |
83
|
|
|
|
|
|
|
EOT |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
The C<#line> directive will point to the line after the C<eval_here> invocation, |
86
|
|
|
|
|
|
|
i.e., the first line of <C$code_to_run>. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
C<$code_to_run> must be defined, but can be empty. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
The return value is the return value of the eval. C<eval_here> does not |
91
|
|
|
|
|
|
|
check C<$@>; that is the caller's responsibility. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub eval_here { |
96
|
6
|
|
|
6
|
1
|
11
|
my $code_to_run = $_[0]; |
97
|
6
|
50
|
|
|
|
15
|
croak "Need a code string to run" unless defined $code_to_run; |
98
|
|
|
|
|
|
|
|
99
|
6
|
|
|
|
|
26
|
my (undef, $filename, $line) = caller; |
100
|
6
|
50
|
33
|
|
|
28
|
die "Couldn't get caller's information" unless $filename && $line; |
101
|
|
|
|
|
|
|
|
102
|
6
|
|
|
|
|
17
|
$filename =~ s/"/-/g; |
103
|
6
|
|
|
|
|
9
|
++$line; |
104
|
|
|
|
|
|
|
|
105
|
6
|
|
|
|
|
375
|
eval <<EOT; |
106
|
|
|
|
|
|
|
#line $line "$filename" |
107
|
|
|
|
|
|
|
$code_to_run |
108
|
|
|
|
|
|
|
EOT |
109
|
|
|
|
|
|
|
} #eval_here() |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
__END__ |
113
|
|
|
|
|
|
|
# vi: set fdm=marker: # |