1PPIx::EditorTools::IntrUosdeurceCToenmtPprPoiIrbxau:rt:yeEVddairPtieoarrblTloeDo(ol3cs)u:m:eInnttartoidounceTemporaryVariable(3)
2
3
4
6 PPIx::EditorTools::IntroduceTemporaryVariable - Introduces a temporary
7 variable using PPI
8
10 my $munged = PPIx::EditorTools::IntroduceTemporaryVariable->new->introduce(
11 code => "use strict; BEGIN {
12 $^W = 1;
13 }\n\tmy $x = ( 1 + 10 / 12 ) * 2;\n\tmy $y = ( 3 + 10 / 12 ) * 2;\n",
14 start_location => [ 2, 19 ],
15 end_location => [ 2, 25 ],
16 varname => '$foo',
17 );
18 my $modified_code_as_string = $munged->code;
19 my $location_of_new_var_declaration = $munged->element->location;
20
22 Given a region of code within a statement, replaces all occurrences of
23 that code with a temporary variable. Declares and initializes the
24 temporary variable right above the statement that included the selected
25 expression.
26
28 new()
29 Constructor. Generally shouldn't be called with any arguments.
30
31 find( ppi => PPI::Document, start_location => Int, end_location => Int,
32 varname => Str ) =item find( code => Str, start_location => Int,
33 end_location => Int, varname => Str )
34 Accepts either a "PPI::Document" to process or a string containing
35 the code (which will be converted into a "PPI::Document") to
36 process.
37
38 Given the region of code specified by start_location and
39 end_location, replaces that code with a temporary variable with the
40 name given in varname (defaults to "tmp"). Declares and initializes
41 the temporary variable right above the statement that included the
42 selected expression.
43
44 Returns a "PPIx::EditorTools::ReturnObject" with the modified code
45 as a string available via the "code" accessor (or as a
46 "PPI::Document" via the "ppi" accessor), and the "PPI::Token" where
47 the new variable is declared available via the "element" accessor.
48
49 Croaks with a "no token" exception if no token is found at the
50 location. Croaks with a "no statement" exception if unable to find
51 the statement.
52
54 This class inherits from "PPIx::EditorTools". Also see
55 App::EditorTools, Padre, and PPI.
56
58 Steffen Mueller "smueller@cpan.org" Mark Grimes "mgrimes@cpan.org"
59
61 Copyright 2008-2009 The Padre development team as listed in Padre.pm.
62
63 This program is free software; you can redistribute it and/or modify it
64 under the same terms as Perl 5 itself.
65
66
67
68perl v5.12.0 PPIx2:0:0E9d-i0t9o-r1T9ools::IntroduceTemporaryVariable(3)