File Coverage

lib/Devel/Trepan/CmdProcessor/Command/Server.pm
Criterion Covered Total %
statement 72 102 70.5
branch n/a
condition n/a
subroutine 24 28 85.7
pod 0 4 0.0
total 96 134 71.6


line stmt bran cond sub pod time code
1             # -*- coding: utf-8 -*-
2             # Copyright (C) 2011-2012, 2014 Rocky Bernstein <rocky@cpan.org>
3 12     12   97 use warnings; no warnings 'redefine';
  12     12   27  
  12     1   376  
  12     1   59  
  12         27  
  12         358  
  1         6  
  1         2  
  1         23  
  1         5  
  1         1  
  1         36  
4              
5 12     12   62 use rlib '../../../..';
  12     1   25  
  12         65  
  1         6  
  1         1  
  1         6  
6              
7             # Our local modules
8             ## use Devel::Trepan::Options; or is it default
9 12     12   9522 use Devel::Trepan::Interface::Server;
  12     1   253507  
  12         840  
  1         377  
  1         2  
  1         49  
10              
11             package Devel::Trepan::CmdProcessor::Command::Server;
12 12     12   98 use Cwd 'abs_path';
  12     1   29  
  12         554  
  1         5  
  1         2  
  1         36  
13 12     12   83 use Getopt::Long qw(GetOptionsFromArray);
  12     1   26  
  12         111  
  1         5  
  1         1  
  1         17  
14 12     12   1798 use if !@ISA, Devel::Trepan::CmdProcessor::Command ;
  12     1   30  
  12         73  
  1         106  
  1         1  
  1         5  
15              
16             unless (@ISA) {
17 12     12   73 eval <<'EOE';
  12     12   27  
  12     12   609  
  12     12   68  
  12         27  
  12         604  
  12         74  
  12         30  
  12         525  
  12         67  
  12         25  
  12         449  
18             use constant CATEGORY => 'support';
19             use constant SHORT_HELP => 'Allow remote debugger connections';
20             use constant MIN_ARGS => 0; # Need at least this many
21             use constant MAX_ARGS => undef; # Need at most this many - undef -> unlimited.
22             EOE
23             }
24              
25 12     12   1890 use strict;
  12     1   28  
  12         298  
  1         58  
  1         2  
  1         34  
26              
27 12     12   61 use vars qw(@ISA); @ISA = qw(Devel::Trepan::CmdProcessor::Command);
  12     1   24  
  12         757  
  1         6  
  1         1  
  1         49  
28 12     12   72 use vars @CMD_VARS; # Value inherited from parent
  12     1   32  
  12         4470  
  1         6  
  1         2  
  1         323  
29              
30             $NAME = set_name();
31             =pod
32              
33             =head2 Synopsis:
34              
35             =cut
36             $HELP = <<'HELP';
37             =pod
38              
39             B<server> [I<options>]
40              
41             options:
42              
43             -p | --port NUMBER
44             -a | --address
45              
46             Suspends interactive debugger session and puts debugger in server mode
47             which opens a socket for debugger connections.
48              
49             =cut
50             HELP
51              
52             # FIXME: put back in help.
53             # Note that the command startup file ${Devel::Trepan::CMD_INITFILE_BASE} is read automatically
54             # via a ${NAME} command the debugger is started.
55              
56             my $DEFAULT_OPTIONS = {
57             port => 1954,
58             host => '127.0.0.1',
59             };
60              
61             # sub complete($$) {
62             # my ($self, $prefix) = @_;
63             # my $files = Readline::FILENAME_COMPLETION_PROC.call(prefix) || []
64             # my $opts = (qw(-c --continue --no-continue -N --no -y --yes
65             # --verbose --no-verbose), $files);
66             # Devel::Trepan::Complete::complete_token($opts, $prefix) ;
67             # }
68              
69             sub parse_options($$)
70             {
71 0     0 0   my ($self, $args) = @_;
  0     0 0    
72 0           my $seen_yes_no = 0;
  0            
73 0           my %opts = %{$DEFAULT_OPTIONS};
  0            
  0            
  0            
74             my $result = &GetOptionsFromArray($args,
75             'port:n' => \$opts{port},
76             'host:s' => \$opts{host},
77 0           );
  0            
78 0           \%opts;
  0            
79             }
80              
81             sub run($$)
82             {
83 0     0 0   my ($self, $args) = @_;
  0     0 0    
84 0           my @args = @$args;
  0            
85 0           my $proc = $self->{proc};
  0            
86 0           my $options = parse_options($self, \@args);
  0            
87 0           my $intf = $proc->{interfaces};
  0            
88 0           $options->{logger} = $intf->[-1]{output}{output};
  0            
89             # Push a new server interface.
90 0           my $script_intf = Devel::Trepan::Interface::Server->new(undef, undef,
  0            
91             $options);
92 0           push @{$intf}, $script_intf;
  0            
  0            
  0            
93             }
94              
95              
96             # Demo it
97             unless (caller) {
98             # require_relative '../mock'
99             # dbgr, cmd = MockDebugger::setup
100             # %w(--quiet -q --no-quiet --continue --no-continue -c -v --verbose
101             # --no-verbose).each do |opt|
102             # puts "parsing ${opt}"
103             # options =
104             # cmd.parse_options(Trepan::Command::SourceCommand::DEFAULT_OPTIONS.dup,
105             # opt)
106             # p options
107             # }
108              
109             # if ARGV.size >= 1
110             # puts "running... ${cmd.name} ${ARGV}"
111             # cmd.run([cmd.name, *ARGV])
112             # }
113             }
114              
115             1;