| 1 | # App::hopen::Util::String - string utilities for hopen | ||||||||||||||||||||||||||||
| 2 | package App::hopen::Util::String; | ||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Data::Hopen; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Data::Hopen::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '0.000013'; # TRIAL | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use parent 'Exporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use vars::i '@EXPORT_OK' => qw(eval_here line_mark_string); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use vars::i '%EXPORT_TAGS' => (all => [@EXPORT_OK]); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | 33 | ▶ | my ($contents, $filename, $line); | ||||||||||||||||||||||||||
|
Subroutine
line_mark_string: called CC=6 SCAR=21.4
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 33 | ▶ | if(@_ == 1) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 57 | 33 | $contents = $_[0]; | |||||||||||||||||||||||||||
| 58 | 33 | (undef, $filename, $line) = caller; | |||||||||||||||||||||||||||
| 59 | } elsif(@_ == 3) { | ||||||||||||||||||||||||||||
| 60 | 0 | ($filename, $line, $contents) = @_; | |||||||||||||||||||||||||||
| 61 | } else { | ||||||||||||||||||||||||||||
| 62 | 0 | croak "Invalid invocation"; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 33 | ▶ | croak "Need text" unless defined $contents; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 33 | ▶ | die "Couldn't get location information" unless $filename && $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$filename and $line
MC/DC0%0/2
$filename and $line
$filename
$line
Truth table33%1/3
A and B
A= $filenameB= $line
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 33 | $filename =~ s/"/-/g; | |||||||||||||||||||||||||||
| 69 | 33 | ++$line; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 33 | 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 | 12 | ▶ | my $code_to_run = $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
eval_here: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 12 | ▶ | croak "Need a code string to run" unless defined $code_to_run; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 12 | my (undef, $filename, $line) = caller; | |||||||||||||||||||||||||||
| 100 | 12 | ▶ | die "Couldn't get caller's information" unless $filename && $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$filename and $line
MC/DC0%0/2
$filename and $line
$filename
$line
Truth table33%1/3
A and B
A= $filenameB= $line
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 12 | $filename =~ s/"/-/g; | |||||||||||||||||||||||||||
| 103 | 12 | ++$line; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 12 | eval <<EOT; | |||||||||||||||||||||||||||
| 106 | #line $line "$filename" | ||||||||||||||||||||||||||||
| 107 | $code_to_run | ||||||||||||||||||||||||||||
| 108 | EOT | ||||||||||||||||||||||||||||
| 109 | } #eval_here() | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 2 | 1; | |||||||||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||||||||||
| 113 | # vi: set fdm=marker: # | ||||||||||||||||||||||||||||