Wrangler.pm

filter: Statementstmt 90.4% 19 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 92.8% 26 / 28 CC 1 SCAR 0.4
CC
1
Cov
90%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Wrangler/Wx/App.pm ↑ Summary
1 package Wrangler;
2  
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  
6 1 ▶use Wrangler::PubSub;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Wrangler::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Wrangler::PluginManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Wrangler::FileSystem::Layers;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 0 ▶use Wrangler::Wx::App;
Subroutine BEGIN: called CC=1 SCAR=2.6
11  
12 our $VERSION = 2.15;
13 our $log = 0;
14 our $wishlist;
15  
16 sub new {
17 my $class = shift;
18 my $self = bless {
19 appname => 'Wrangler',
20 version => $VERSION,
21 @_
22 }, $class;
23  
24 ## load config
25 Wrangler::Config::read();
26  
27 ## simple CLI switch parsing
28 if(@ARGV){
29 for(@ARGV){
30 if($_ eq '--debug'){
31 $self->{debug} = 1;
32 $log = 1; # $log is non-OO for efficiency
33 }elsif($_ =~ /^\/|^\\/){
34 $Wrangler::Config::env{CLI_ChangeDirectory} = $_;
35 }
36 }
37 }
38  
39 ## establish PluginManager
40 Wrangler::PluginManager::load_plugins($self);
41  
42 ## establish our virtual file-system
43 $self->{fs} = Wrangler::FileSystem::Layers->new();
44  
45 Wrangler::PubSub::subscribe('file.activated', \&OnActivated,__PACKAGE__);
46 Wrangler::PubSub::subscribe('main.menubar.toggle', sub {
47 $self->{main}->OnToggleMenuBar($_[0]);
48 },__PACKAGE__);
49 Wrangler::PubSub::subscribe('main.navbar.toggle', sub {
50 $self->{main}->OnToggleNavbar($_[0]);
51 },__PACKAGE__);
52 Wrangler::PubSub::subscribe('main.sidebar.toggle', sub {
53 $self->{main}->OnToggleSidebar($_[0]);
54 },__PACKAGE__);
55 Wrangler::PubSub::subscribe('main.statusbar.toggle', sub {
56 $self->{main}->OnToggleStatusBar($_[0]);
57 },__PACKAGE__);
58 Wrangler::PubSub::subscribe('main.formeditor.recreate', sub {
59 $self->{main}->OnReCreateFormEditor($_[0]);
60 },__PACKAGE__);
61 Wrangler::PubSub::publish('status.update', "Init complete");
62  
63 return $self;
64 }
65  
66 sub config {
67 Wrangler::Config::config(@_);
68 }
69  
70 sub debug {
71 print $_[0] . "\n" if $log;
72 }
73  
74 sub wishlist {
75 # use Data::Dumper;
76 # print 'Wrangler::wishlist:'.Dumper($wishlist);
77 return [ keys %$wishlist ];
78 }
79  
80 sub run {
81 my $self = shift;
82  
83 ## create the Wx App and its main window
84 my $app = Wrangler::Wx::App->new(); # Create the application object
85 $self->{main} = $app->create($self);
86 $app->MainLoop; # Start event processing
87 }
88  
89 sub OnActivated {
90 Wrangler::debug("Main:: received event 'file.activated': @_");
91 my ($path,$richlist_item) = @_;
92  
93 if($richlist_item->{'MIME::mediaType'}){
94 my $viewers = $Wrangler::Config::settings{'openwith'};
95 if( $viewers->{ $richlist_item->{'MIME::mediaType'} . '/*' } ){
96 Wrangler::debug(" mediaType ".$richlist_item->{'MIME::mediaType'} ." has association ". $viewers->{ $richlist_item->{'MIME::mediaType'} . '/*' } .", appending path $richlist_item->{'Filesystem::Path'}) ");
97 my $pid = ForkAndExec($viewers->{ $richlist_item->{'MIME::mediaType'} . '/*' }, $richlist_item->{'Filesystem::Path'} );
98 Wrangler::PubSub::publish('status.update',"Launched external viewer with pid $pid");
99 return;
100 }
101 }
102  
103 Wrangler::debug("No viewer associated or MIME::mediaType unknown. returning. ");
104 }
105  
106 sub ForkAndExec {
107 my @commands = @_;
108  
109 my $pid = fork();
110  
111 print STDERR "unable to fork: $!" unless defined($pid);
112 return undef unless defined($pid);
113  
114 # contains no pid when we're in the forked child
115 if(!$pid){
116 exec(@commands);
117 die "unable to exec: $!";
118 }
119  
120 return $pid if $pid;
121 }
122  
123 sub DESTROY {
124 Wrangler::debug("Wrangler::DESTROY");
125  
126 ## store config if it has changed
127 Wrangler::Config::write()
128 }
129  
130 1;
131  
132 __END__
« Wrangler/Wx/App.pm ↑ Summary