Changeset 2228
- Timestamp:
- 12/28/08 17:01:15 (3 years ago)
- Location:
- trunk/Padre
- Files:
-
- 2 edited
-
lib/Padre/PluginManager.pm (modified) (9 diffs)
-
t/82-plugin-manager.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre/lib/Padre/PluginManager.pm
r2226 r2228 274 274 my $plugins = $self->plugins; 275 275 return grep { 276 $plugins->{$_}->{status} eq ' failed'276 $plugins->{$_}->{status} eq 'error' 277 277 } keys %$plugins; 278 278 } … … 385 385 $@, 386 386 ); 387 $plugin->status(' failed');387 $plugin->status('error'); 388 388 return; 389 389 } … … 397 397 ), $name, 398 398 ); 399 $plugin->status(' failed');399 $plugin->status('error'); 400 400 return; 401 401 } … … 409 409 ), $name, 410 410 ); 411 $plugin->status(' failed');411 $plugin->status('error'); 412 412 return; 413 413 } … … 422 422 $name, 423 423 ); 424 $plugin->status(' failed');424 $plugin->status('error'); 425 425 return; 426 426 } … … 431 431 # TODO report error in a nicer way 432 432 $self->{errstr} = $@; 433 $plugin->status(' failed');433 $plugin->status('error'); 434 434 return; 435 435 } … … 442 442 $name, 443 443 ); 444 $plugin->status(' failed');444 $plugin->status('error'); 445 445 return; 446 446 } … … 503 503 # Unload the plugin class itself 504 504 require Class::Unload; 505 Class::Unload->unload($handle-> module);505 Class::Unload->unload($handle->class); 506 506 507 507 # Finally, remove the handle (and flush the sort order) … … 696 696 $config->{plugins}->{$filename}->{enabled} = 1; 697 697 $self->load_plugin($filename); 698 if ( $self->plugins->{$filename}->{status} eq ' failed' ) {698 if ( $self->plugins->{$filename}->{status} eq 'error' ) { 699 699 $main->error(sprintf(Wx::gettext("Failed to load the plugin '%s'"), $filename)); 700 700 return; -
trunk/Padre/t/82-plugin-manager.t
r2169 r2228 4 4 use warnings; 5 5 6 use FindBin qw($Bin);7 use File::Spec ();8 use Data::Dumper qw(Dumper);9 10 6 use Test::More; 11 7 BEGIN { 12 if (not $ENV{DISPLAY} and not $^O eq 'MSWin32') {8 unless ( $ENV{DISPLAY} or $^O eq 'MSWin32' ) { 13 9 plan skip_all => 'Needs DISPLAY'; 14 10 exit 0; … … 16 12 } 17 13 18 plan tests => 2 5;14 plan tests => 23; 19 15 16 use FindBin qw($Bin); 17 use File::Spec (); 18 use Data::Dumper qw(Dumper); 20 19 use Test::NoWarnings; 21 22 20 use t::lib::Padre; 23 21 use Padre; 22 use Padre::PluginManager; 24 23 25 use_ok('Padre::PluginManager');24 my $padre = Padre->new; 26 25 27 my $padre = Padre->new(); 28 my $plugin_m1 = Padre::PluginManager->new($padre); 29 isa_ok $plugin_m1, 'Padre::PluginManager'; 26 # Test the default loading behaviour 27 SCOPE: { 28 my $manager = Padre::PluginManager->new($padre); 29 isa_ok( $manager, 'Padre::PluginManager' ); 30 is( 31 $manager->plugin_dir, 32 Padre::Config->default_plugin_dir, 33 '->default_plugin_dir ok', 34 ); 35 is( keys %{$manager->plugins}, 0, 'Found no plugins' ); 36 ok( 37 ! defined($manager->load_plugins()), 38 'load_plugins always returns undef' 39 ); 30 40 31 is $plugin_m1->plugin_dir, Padre::Config->default_plugin_dir; 32 is keys %{$plugin_m1->plugins}, 0; 33 34 ok !defined($plugin_m1->load_plugins()), 'load_plugins always returns undef'; 35 36 37 # check if we have the plugins that come with Padre 38 cmp_ok (keys %{$plugin_m1->plugins}, '>=', 1); 39 #is $plugin_m1->plugins->{'Development::Tools'}, 'Padre::Plugin::Development::Tools'; 40 ok !$plugin_m1->plugins->{'Development::Tools'}, 'no second level plugin'; 41 42 # try load again 43 #{ 44 #my $st = $plugin_m1->load_plugin('Development::Tools'); 45 #is $st, undef; 46 #} 41 # check if we have the plugins that come with Padre 42 cmp_ok( keys %{$manager->plugins}, '>=', 1, 'Loaded at least one plugin' ); 43 ok( ! $manager->plugins->{'Development::Tools'}, 'No second level plugin' ); 44 } 47 45 48 46 ## Test loading single plugins 49 $plugin_m1 = Padre::PluginManager->new($padre); 50 is keys %{$plugin_m1->plugins}, 0;51 ok(!$plugin_m1->load_plugin('My'));52 is keys %{$plugin_m1->plugins}, 1;53 is( $plugin_m1->plugins->{My}{status}, 'disabled' );54 $padre->config->{plugins}{My}{enabled} = 1;55 ok($plugin_m1->load_plugin('My'));56 is( $plugin_m1->plugins->{My}{status}, 'enabled' );57 ok($plugin_m1->reload_plugin('My'));58 is( $plugin_m1->plugins->{My}{status}, 'enabled' );59 ok($plugin_m1->unload_plugin('My'));60 ok( !defined($plugin_m1->plugins->{My}));61 47 SCOPE: { 48 my $manager = Padre::PluginManager->new($padre); 49 is( keys %{$manager->plugins}, 0, 'No plugins loaded' ); 50 ok( ! $manager->load_plugin('My'), 'Loaded My Plugin' ); 51 is( keys %{$manager->plugins}, 1, 'Loaded something' ); 52 my $handle = $manager->_plugin('My'); 53 isa_ok( $handle, 'Padre::PluginHandle' ); 54 is( $handle->name, 'My', 'Loaded My Plugin' ); 55 ok( $handle->disabled, 'My Plugin is disabled' ); 56 ok( $manager->unload_plugin('My'), '->unload_plugin ok' ); 57 ok( ! defined($manager->plugins->{My}), 'Plugin no longer loaded' ); 58 is( eval("\$Padre::Plugin::My::VERSION"), undef, 'My Plugin was cleaned up' ); 59 } 62 60 63 61 ## Test With custom plugins 64 my $custom_dir = File::Spec->catfile( $Bin, 'lib' ); 65 my $plugin_m2 = Padre::PluginManager->new($padre, plugin_dir => $custom_dir); 62 SCOPE: { 63 my $custom_dir = File::Spec->catfile( $Bin, 'lib' ); 64 my $manager = Padre::PluginManager->new($padre, plugin_dir => $custom_dir); 65 is( $manager->plugin_dir, $custom_dir ); 66 is( keys %{$manager->plugins}, 0 ); 66 67 67 is $plugin_m2->plugin_dir, $custom_dir; 68 is keys %{$plugin_m2->plugins}, 0; 68 $manager->_load_plugins_from_inc; 69 # cannot compare with the exact numbers as there might be plugins already installed 70 cmp_ok(keys %{$manager->plugins}, '>=', 3, 'at least 3 plugins') 71 or 72 diag(Dumper(\$manager->plugins)); 69 73 70 $plugin_m2->_load_plugins_from_inc(); 71 # cannot compare with the exact numbers as there might be plugins already installed 72 cmp_ok (keys %{$plugin_m2->plugins}, '>=', 3, 'at least 3 plugins') 73 or diag(Dumper(\$plugin_m2->plugins)); 74 ok( ! exists $manager->plugins->{'Development::Tools'}, 'no second level plugin' ); 75 is( $manager->_plugin('TestPlugin')->class, 'Padre::Plugin::TestPlugin' ); 76 ok( !defined $manager->plugins->{'Test::Plugin'}, 'no second level plugin' ); 74 77 75 #is $plugin_m2->plugins->{'Development::Tools'}, 'Padre::Plugin::Development::Tools'; 76 ok !exists $plugin_m2->plugins->{'Development::Tools'}, 'no second level plugin'; 77 is $plugin_m2->plugins->{TestPlugin}{module}, 'Padre::Plugin::TestPlugin'; 78 #is $plugin_m2->plugins->{'Test::Plugin'}, 'Padre::Plugin::Test::Plugin'; 79 ok !defined $plugin_m2->plugins->{'Test::Plugin'}, 'no second level plugin'; 80 81 # try load again 82 { 83 my $st = $plugin_m2->load_plugin('TestPlugin'); 84 is $st, undef; 78 # try load again 79 my $st = $manager->load_plugin('TestPlugin'); 80 is( $st, undef ); 85 81 } 86 87 ### XXX? TODO, test par88 89 1;
Note: See TracChangeset
for help on using the changeset viewer.
