Ticket #66: par_plugin_support.diff
| File par_plugin_support.diff, 4.1 KB (added by tsee, 5 years ago) |
|---|
-
lib/Padre.pm
206 206 config_dir => undef, 207 207 config_yaml => undef, 208 208 config_db => undef, 209 plugin_dir => undef, 209 210 recent => { 210 211 files => [], 211 212 pod => [], … … 216 217 $self->{config_dir} = Padre::Config->default_dir; 217 218 $self->{config_yaml} = Padre::Config->default_yaml; 218 219 $self->{config_db} = Padre::Config->default_db; 220 $self->{plugin_dir} = Padre::Config->default_plugin_dir; 219 221 220 222 $self->load_config; 221 223 $self->_process_command_line; … … 285 287 286 288 sub _locate_plugins { 287 289 my ($self) = @_; 288 my %plugins; 290 291 # Try the plugin directory first: 292 my $plugin_dir = $self->{plugin_dir}; 293 unshift @INC, $plugin_dir unless grep {$_ eq $plugin_dir} @INC; 294 289 295 foreach my $path (@INC) { 290 296 my $dir = File::Spec->catdir($path, 'Padre', 'Plugin'); 291 297 opendir my $dh, $dir or next; 292 298 while (my $file = readdir $dh) { 293 299 if ($file =~ /^\w+\.pm$/) { 294 300 $file =~ s/\.pm$//; 295 $plugins{$file} = 0; 296 my $module = "Padre::Plugin::$file"; 297 eval "use $module"; ## no critic 298 if ($@) { 299 warn "ERROR while trying to load plugin '$file': $@"; 300 next; 301 } 302 303 $plugins{$file} = $module; 301 $self->_load_plugin($file); 304 302 } 305 303 } 306 304 } 307 $self->{plugins} = \%plugins; 305 306 $self->_locate_plugins_in_par(); 308 307 return; 309 308 } 310 309 310 sub _load_plugin { 311 my ($self, $file) = @_; 312 my $plugins = $self->{plugins} || {}; 313 $plugins->{$file} = 0; 314 315 my $module = "Padre::Plugin::$file"; 316 eval "use $module"; ## no critic 317 if ($@) { 318 warn "ERROR while trying to load plugin '$file': $@"; 319 return(); 320 } 321 $plugins->{$file} = $module; 322 $self->{plugins} = $plugins; 323 return 1; 324 } 325 326 sub _locate_plugins_in_par { 327 my ($self) = @_; 328 329 # setup the PAR environment: 330 my $plugin_dir = $self->{plugin_dir}; 331 my $cache_dir = File::Spec->catdir($plugin_dir, 'cache'); 332 $ENV{PAR_GLOBAL_TEMP} = $cache_dir; 333 File::Path::mkpath($cache_dir) if not -e $cache_dir; 334 $ENV{PAR_TEMP} = $cache_dir; 335 336 require PAR; 337 338 opendir my $dh, $plugin_dir or return; 339 while (my $file = readdir $dh) { 340 if ($file =~ /^\w+\.par$/i) { 341 my $parfile = File::Spec->catfile($plugin_dir, $file); 342 $file =~ s/\.par$//i; 343 PAR->import($parfile); 344 $self->_load_plugin($file); 345 } 346 } 347 closedir($dh); 348 return; 349 } 350 311 351 sub usage { 312 352 die <<"END_USAGE"; 313 353 Usage: $0 [FILENAMEs] -
lib/Padre/Config.pm
3 3 use 5.008; 4 4 use strict; 5 5 use warnings; 6 use File::Path (); 6 7 use File::Spec (); 7 8 use File::HomeDir (); 8 9 use YAML::Tiny (); … … 43 44 ); 44 45 } 45 46 47 sub default_plugin_dir { 48 my $pluginsdir = File::Spec->catdir( 49 $_[0]->default_dir, 50 'plugins', 51 ); 52 my $plugins_full_path = File::Spec->catdir( 53 $pluginsdir, 'Padre', 'Plugin' 54 ); 55 unless ( -e $plugins_full_path) { 56 File::Path::mkpath($plugins_full_path) or 57 die "Cannot create plugins dir '$plugins_full_path' $!"; 58 } 46 59 60 return $pluginsdir; 61 } 47 62 48 63 49 64 65 66 50 67 ##################################################################### 51 68 # Constructor and Serialization 52 69 -
Build.PL
26 26 'File::Slurp' => 0, 27 27 'Module::Inspector' => '0.04', 28 28 'ORLite' => '0.10', 29 'PAR' => '0.970', 29 30 'Pod::POM' => 0, 30 31 'Pod::Simple' => 0, 31 32 'Probe::Perl' => '0.01',
