SOOT/App.pm

filter: Statementstmt 88.2% 15 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.3% 21 / 23 CC 1 SCAR 0.5
CC
1
Cov
88%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Devel/REPL/Plugin/SOOT.pm ↑ Summary
1 package SOOT::App;
2 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Getopt::Long ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 0 ▶use threads;
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use Capture::Tiny qw/capture/;
9 use Time::HiRes 'usleep';
10 use vars '%SIG';
11  
12 our $VERSION = '0.04';
13 our $AppThread;
14  
15 sub usage {
16 print <<'HERE';
17 Usage: soot [options]
18  
19 -n Do not execute logon macros
20 HERE
21 exit(1);
22 }
23  
24 sub run {
25 my $class = shift;
26  
27 my %opts = @_;
28 my $argv = $opts{argv}||[];
29  
30 my $nologon = 0;
31 Getopt::Long::GetOptionsFromArray(
32 $argv,
33 'h|help' => \&usage,
34 'n' => \$nologon,
35 );
36  
37 my @files_to_open = @$argv;
38 require Devel::REPL;
39 require SOOT;
40 require Devel::REPL::Plugin::CompletionDriver::SOOT;
41  
42 my $repl = Devel::REPL->new;
43 foreach (qw(FindVariable History LexEnv Packages SOOT)) {
44 $repl->load_plugin($_)
45 }
46 foreach (qw(Colors CompletionDriver::SOOT Completion DDS Interrupt
47 MultiLine::PPI OutputCache PPI)) {
48 my @discard = capture {
49 eval {
50 $repl->load_plugin($_);
51 1;
52 } or die $@;
53 };
54 }
55 create_app_thread();
56 package main;
57 SOOT->import(':all');
58 # FIXME: mst will likely kill me for this
59 $repl->formatted_eval("package main;");
60 $repl->formatted_eval("no strict 'vars'");
61 $repl->formatted_eval("use SOOT qw/:all/");
62 $repl->formatted_eval("use Data::Dumper;");
63 SOOT::Init($nologon ? 0 : 1);
64  
65 $class->_open_root_files(\@files_to_open);
66  
67 return $repl->run();
68 }
69  
70 sub _open_root_files {
71 my $class = shift;
72 my $files = shift;
73  
74 no strict 'vars';
75 package main;
76 foreach my $file (map {glob $_} @$files) {
77 my $f = TFile->new($file, 'READ');
78 push @files, $f;
79 print "Attached file '$file' as \$main::files[" . $#main::files . "]...\n";
80 }
81 return();
82 }
83  
84 sub create_app_thread {
85 if (not $AppThread) {
86 $SOOT::gApplication->SetReturnFromRun(1);
87 $AppThread = threads->new(\&apploop);
88 usleep(5000); # FIXME find better way to fix this
89 $SOOT::gApplication->SetReturnFromRun(1);
90 }
91 }
92  
93 sub apploop {
94 $SOOT::gApplication->SetReturnFromRun(1);
95 $SOOT::gApplication->Run();
96 }
97  
98 sub kill_app_thread {
99 return if !$AppThread;
100 $SOOT::gApplication->Terminate();
101 $AppThread->kill('TERM')->kill('KILL')->detach;
102 $AppThread = undef;
103 }
104  
105 END {
106 kill_app_thread();
107 }
108  
109 SCOPE: {
110 my %sig;
111 sub init_signal_handlers {
112 if (not keys %sig) {
113 %sig = %SIG;
114 $SIG{TERM} = sub { kill_app_thread(); return $sig{TERM}->() if ref($SIG{TERM}) eq 'CODE' };
115 $SIG{INT} = sub { kill_app_thread(); return $sig{INT}->() if ref($SIG{INT}) eq 'CODE' };
116 }
117 }
118 }
119  
120 1;
121 __END__
« Devel/REPL/Plugin/SOOT.pm ↑ Summary