Import original source of Eval-LineNumbers 0.34
gregor herrmann
10 years ago
0 | ||
1 | Revision history for Perl module Eval::LineNumbers | |
2 | ||
3 | 0.34 2013/10/07 | |
4 | ||
5 | - Fix Makefile.PL NAME | |
6 | ||
7 | 0.33 2013/10/04 | |
8 | ||
9 | - Complete makeover by Olivier MenguĂ: | |
10 | - add caller-level support | |
11 | - add a test | |
12 | - fix typos, groom makefile and code | |
13 | ||
14 | 0.32 2013/10/01 | |
15 | ||
16 | - use 'heredoc' instead of 'hereis' | |
17 | - add Google copyright | |
18 | - rename CHANGELOG to Changes | |
19 | - add README | |
20 | - create git repository, add link | |
21 | ||
22 | 0.31 2009/09/01 | |
23 | ||
24 | - Minor documentation changes. | |
25 | ||
26 | 0.3 2009/07/24 | |
27 | ||
28 | - Initial version |
0 | Changes | |
1 | lib/Eval/LineNumbers.pm | |
2 | Makefile.PL | |
3 | MANIFEST | |
4 | MANIFEST.SKIP | |
5 | META.yml | |
6 | README | |
7 | t/basic.t | |
8 | META.json Module JSON meta-data (added by MakeMaker) |
0 | ||
1 | # Avoid version control files. | |
2 | \bRCS\b | |
3 | \bCVS\b | |
4 | \bSCCS\b | |
5 | ,v$ | |
6 | \B\.svn\b | |
7 | \B\.git\b | |
8 | \B\.gitignore\b | |
9 | \b_darcs\b | |
10 | \B\.cvsignore$ | |
11 | ||
12 | # Avoid VMS specific MakeMaker generated files | |
13 | \bDescrip.MMS$ | |
14 | \bDESCRIP.MMS$ | |
15 | \bdescrip.mms$ | |
16 | ||
17 | # Avoid Makemaker generated and utility files. | |
18 | \bMANIFEST\.bak | |
19 | \bMakefile$ | |
20 | \bblib/ | |
21 | \bMakeMaker-\d | |
22 | \bpm_to_blib\.ts$ | |
23 | \bpm_to_blib$ | |
24 | \bblibdirs\.ts$ # 6.18 through 6.25 generated this | |
25 | ||
26 | # Avoid Module::Build generated and utility files. | |
27 | \bBuild$ | |
28 | \b_build/ | |
29 | \bBuild.bat$ | |
30 | \bBuild.COM$ | |
31 | \bBUILD.COM$ | |
32 | \bbuild.com$ | |
33 | ||
34 | # Avoid temp and backup files. | |
35 | ~$ | |
36 | \.old$ | |
37 | \#$ | |
38 | \b\.# | |
39 | \.bak$ | |
40 | \.tmp$ | |
41 | \.# | |
42 | \.rej$ | |
43 | \..*\.sw.$ | |
44 | ||
45 | # Avoid OS-specific files/dirs | |
46 | # Mac OSX metadata | |
47 | \B\.DS_Store | |
48 | # Mac OSX SMB mount metadata files | |
49 | \B\._ | |
50 | ||
51 | # Avoid Devel::Cover and Devel::CoverX::Covered files. | |
52 | \bcover_db\b | |
53 | \bcovered\b | |
54 | ||
55 | # Avoid MYMETA files | |
56 | ^MYMETA\. | |
57 | ||
58 | Eval-LineNumbers-* |
0 | { | |
1 | "abstract" : "Add line numbers to eval'ed heredoc blocks", | |
2 | "author" : [ | |
3 | "David Muir Sharnoff <cpan@dave.sharnoff.org>" | |
4 | ], | |
5 | "dynamic_config" : 1, | |
6 | "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150", | |
7 | "license" : [ | |
8 | "unknown" | |
9 | ], | |
10 | "meta-spec" : { | |
11 | "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", | |
12 | "version" : "2" | |
13 | }, | |
14 | "name" : "Eval-LineNumbers", | |
15 | "no_index" : { | |
16 | "directory" : [ | |
17 | "t", | |
18 | "inc" | |
19 | ] | |
20 | }, | |
21 | "prereqs" : { | |
22 | "build" : { | |
23 | "requires" : { | |
24 | "ExtUtils::MakeMaker" : 0 | |
25 | } | |
26 | }, | |
27 | "configure" : { | |
28 | "requires" : { | |
29 | "ExtUtils::MakeMaker" : 0 | |
30 | } | |
31 | }, | |
32 | "runtime" : { | |
33 | "requires" : { | |
34 | "Exporter" : "5.57" | |
35 | } | |
36 | } | |
37 | }, | |
38 | "release_status" : "stable", | |
39 | "resources" : { | |
40 | "repository" : { | |
41 | "url" : "http://github.com/muir/Eval-LineNumbers" | |
42 | } | |
43 | }, | |
44 | "version" : "0.34" | |
45 | } |
0 | --- | |
1 | abstract: "Add line numbers to eval'ed heredoc blocks" | |
2 | author: | |
3 | - 'David Muir Sharnoff <cpan@dave.sharnoff.org>' | |
4 | build_requires: | |
5 | ExtUtils::MakeMaker: 0 | |
6 | configure_requires: | |
7 | ExtUtils::MakeMaker: 0 | |
8 | dynamic_config: 1 | |
9 | generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150' | |
10 | license: unknown | |
11 | meta-spec: | |
12 | url: http://module-build.sourceforge.net/META-spec-v1.4.html | |
13 | version: 1.4 | |
14 | name: Eval-LineNumbers | |
15 | no_index: | |
16 | directory: | |
17 | - t | |
18 | - inc | |
19 | requires: | |
20 | Exporter: 5.57 | |
21 | resources: | |
22 | repository: http://github.com/muir/Eval-LineNumbers | |
23 | version: 0.34 |
0 | use ExtUtils::MakeMaker; | |
1 | ||
2 | WriteMakefile( | |
3 | 'VERSION_FROM' => 'lib/Eval/LineNumbers.pm', | |
4 | 'NAME' => 'Eval::LineNumbers', | |
5 | 'dist' => { COMPRESS=>"gzip", SUFFIX=>"gz" }, | |
6 | 'PREREQ_PM' => { | |
7 | 'Exporter' => '5.57', # in core since 5.8.3, and also on CPAN | |
8 | }, | |
9 | ($] >= 5.005 | |
10 | ? | |
11 | ( | |
12 | ABSTRACT => "Add line numbers to eval'ed heredoc blocks", | |
13 | AUTHOR => 'David Muir Sharnoff <cpan@dave.sharnoff.org>', | |
14 | META_MERGE => { | |
15 | resources => { | |
16 | repository => 'http://github.com/muir/Eval-LineNumbers', | |
17 | }, | |
18 | }, | |
19 | ) | |
20 | : () | |
21 | ), | |
22 | ); | |
23 | ||
24 | package MY; | |
25 | ||
26 | sub postamble { | |
27 | <<"END_OF_POSTAMBLE"; | |
28 | ||
29 | pm_to_blib: README | |
30 | ||
31 | README: lib/Eval/LineNumbers.pm | |
32 | \tpod2text lib/Eval/LineNumbers.pm >README | |
33 | ||
34 | END_OF_POSTAMBLE | |
35 | } | |
36 |
0 | NAME | |
1 | Eval::LineNumbers - Add line numbers to heredoc blocks that contain perl | |
2 | source code | |
3 | ||
4 | SYNOPSIS | |
5 | use Eval::LineNumbers qw(eval_line_numbes); | |
6 | ||
7 | eval eval_line_numbers(<<END_HEREIS); | |
8 | code | |
9 | END_HEREIS | |
10 | ||
11 | eval eval_line_numbers($caller_level, $code) | |
12 | ||
13 | DESCRIPTION | |
14 | Add a "#line "this-file" 392" comment to heredoc/hereis text that is | |
15 | going to be eval'ed so that error messages will point back to the right | |
16 | place. | |
17 | ||
18 | Please note: when you embed "\n" in your code, it gets expanded in | |
19 | double-quote hereis documents so it will mess up your line numbering. | |
20 | Use "\\n" instead when you can. | |
21 | ||
22 | Caller Level Example | |
23 | The second form of eval_line_numbers where a caller-level is provided is | |
24 | for the situation where the code is generated in one place and eval'ed | |
25 | in another place. The caller level should be the number of stack levels | |
26 | between where the heredoc was created and where it is eval'ed. | |
27 | ||
28 | sub example { | |
29 | return <<END_HEREIS | |
30 | code | |
31 | END_HEREIS | |
32 | } | |
33 | ||
34 | eval eval_line_numbers(1, example()) | |
35 | ||
36 | LICENSE | |
37 | Copyright (C) 2009 David Muir Sharnoff. Copyright (C) 2013 Google, Inc. | |
38 | ||
39 | This package may be used and redistributed under the terms of either the | |
40 | Artistic 2.0 or LGPL 2.1 license. | |
41 |
0 | ||
1 | package Eval::LineNumbers; | |
2 | ||
3 | use warnings; | |
4 | use strict; | |
5 | ||
6 | use Exporter 5.57 'import'; | |
7 | our @EXPORT_OK = qw(eval_line_numbers); | |
8 | ||
9 | our $VERSION = 0.34; | |
10 | ||
11 | sub eval_line_numbers | |
12 | { | |
13 | my(undef, $file, $line) = caller( | |
14 | # Optional first arg is the caller level | |
15 | $_[0] =~ /^[0-9]+$/ ? (shift) : 0 | |
16 | ); | |
17 | $line++; | |
18 | return join('', qq{#line $line "$file"\n}, @_) | |
19 | } | |
20 | 1; | |
21 | ||
22 | __END__ | |
23 | ||
24 | =head1 NAME | |
25 | ||
26 | Eval::LineNumbers - Add line numbers to heredoc blocks that contain perl source code | |
27 | ||
28 | =head1 SYNOPSIS | |
29 | ||
30 | use Eval::LineNumbers qw(eval_line_numbes); | |
31 | ||
32 | eval eval_line_numbers(<<END_HEREIS); | |
33 | code | |
34 | END_HEREIS | |
35 | ||
36 | eval eval_line_numbers($caller_level, $code) | |
37 | ||
38 | =head1 DESCRIPTION | |
39 | ||
40 | Add a C<#line "this-file" 392> comment to heredoc/hereis text that is going | |
41 | to be eval'ed so that error messages will point back to the right place. | |
42 | ||
43 | Please note: when you embed C<\n> in your code, it gets expanded in | |
44 | double-quote hereis documents so it will mess up your line numbering. | |
45 | Use C<\\n> instead when you can. | |
46 | ||
47 | =head2 Caller Level Example | |
48 | ||
49 | The second form of eval_line_numbers where a caller-level is provided | |
50 | is for the situation where the code is generated in one place and | |
51 | eval'ed in another place. The caller level should be the number of | |
52 | stack levels between where the heredoc was created and where it is | |
53 | eval'ed. | |
54 | ||
55 | sub example { | |
56 | return <<END_HEREIS | |
57 | code | |
58 | END_HEREIS | |
59 | } | |
60 | ||
61 | eval eval_line_numbers(1, example()) | |
62 | ||
63 | =head1 LICENSE | |
64 | ||
65 | Copyright (C) 2009 David Muir Sharnoff. | |
66 | Copyright (C) 2013 Google, Inc. | |
67 | ||
68 | This package may be used and redistributed under the terms of either | |
69 | the Artistic 2.0 or LGPL 2.1 license. | |
70 |
0 | use strict; | |
1 | use warnings; | |
2 | use Test::More tests => 4; | |
3 | ||
4 | use Eval::LineNumbers 'eval_line_numbers'; | |
5 | ||
6 | ||
7 | my $line_expected = __LINE__ + 3; | |
8 | my ($line, $file) = eval eval_line_numbers <<'EOF'; | |
9 | ||
10 | (__LINE__, __FILE__) | |
11 | ||
12 | EOF | |
13 | ||
14 | is($file, __FILE__, 'file matches'); | |
15 | is($line, $line_expected, 'line number matches'); | |
16 | ||
17 | ||
18 | sub evaluator | |
19 | { | |
20 | eval eval_line_numbers(@_) | |
21 | } | |
22 | ||
23 | $line_expected = __LINE__ + 3; | |
24 | ($line, $file) = evaluator(1, <<'EOF'); | |
25 | ||
26 | (__LINE__, __FILE__) | |
27 | ||
28 | EOF | |
29 | ||
30 | is($file, __FILE__, 'file matches with call level 1'); | |
31 | is($line, $line_expected, 'line number matches with call level 1'); |