« blib/lib/Devel/Trepan/CmdProcessor/Command/Set_Subcmd/Substitute_Subcmd/Path.pm
↑ Summary
lib/Devel/Trepan/DB/Colors.pm »
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | # Copyright (C) 2013-2014 Rocky Bernstein <rocky@cpan.org> | ||
| 3 | use warnings; no warnings 'redefine'; no warnings 'once'; | ||
| 4 | use rlib '../../../../../..'; | ||
| 5 | |||
| 6 | package Devel::Trepan::CmdProcessor::Command::Set::Substitute::String; | ||
| 7 | use Devel::Trepan::DB::LineCache; | ||
| 8 | |||
| 9 | use Devel::Trepan::CmdProcessor::Command::Subcmd::Subsubcmd; | ||
| 10 | use strict; | ||
| 11 | use vars qw(@ISA @SUBCMD_VARS); | ||
| 12 | @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subsubcmd); | ||
| 13 | |||
| 14 | # Values inherited from parent | ||
| 15 | |||
| 16 | use vars @Devel::Trepan::CmdProcessor::Command::Subsubcmd::SUBCMD_VARS; | ||
| 17 | our $CMD = 'set display eval'; | ||
| 18 | my @DISPLAY_TYPES = @Devel::Trepan::CmdProcessor::DISPLAY_TYPES; | ||
| 19 | my $param = join('|', @DISPLAY_TYPES); | ||
| 20 | =pod | ||
| 21 | |||
| 22 | =head2 Synopsis: | ||
| 23 | |||
| 24 | =cut | ||
| 25 | our $HELP = <<"HELP"; | ||
| 26 | =pod | ||
| 27 | |||
| 28 | B<set substitute string> [I<from-file>] I<string> | ||
| 29 | |||
| 30 | Use the contents of string variable I<string-var> as the source text for | ||
| 31 | I<from-file>. If a substitution rule was previously set for | ||
| 32 | I<from-file>, the old rule is replaced by the new one. If I<from_file> | ||
| 33 | is not given use the current filename. | ||
| 34 | =cut | ||
| 35 | HELP | ||
| 36 | |||
| 37 | our $MIN_ABBREV = length('st'); | ||
| 38 | use constant MIN_ARGS => 1; | ||
| 39 | use constant MAX_ARGS => 2; | ||
| 40 | our $SHORT_HELP = 'Use STRING in place of a filename'; | ||
| 41 | |||
| 42 | sub run($$) | ||
| 43 | { | ||
| 44 | my ($self, $args) = @_; | ||
| 45 | my ($from_file, $string); | ||
| 46 | my $proc = $self->{proc}; | ||
| 47 | if (scalar(@$args) == 5) { | ||
| 48 | $from_file = $args->[3]; | ||
| 49 | $string = $args->[4]; | ||
| 50 | } else { | ||
| 51 | $from_file = $proc->{frame}{file}; | ||
| 52 | $string = $args->[3]; | ||
| 53 | } | ||
| 54 | |||
| 55 | my $opts = {return_type => '$', | ||
| 56 | fix_file_and_line => 1, | ||
| 57 | }; | ||
| 58 | my $string_value = eval($string); | ||
| 59 | |||
| 60 | # FIXME: Check string name to see if it is loaded | ||
| 61 | |||
| 62 | if (!$@ && defined($string_value)) { | ||
| 63 | my $filename = remap_string_to_tempfile($string_value); | ||
| 64 | remap_file($from_file, $filename); | ||
| 65 | $proc->msg("Temporary file ${filename} with string contents created"); | ||
| 66 | } else { | ||
| 67 | $proc->errmsg("Can't get string value"); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | unless(caller) { | ||
| 72 | # requre File::Basename; | ||
| 73 | # Demo it. | ||
| 74 | # my $name = basename(__FILE__, '.pm') | ||
| 75 | } | ||
| 76 | |||
| 77 | 1; |