| 1 | package Padre::Plugin::Moose::Role::NeedsPluginEvent; | ||
| 2 | use Moose::Role; | ||
| 3 | |||
| 4 | requires 'on_save_as'; | ||
| 5 | requires 'new_document_from_string'; | ||
| 6 | |||
| 7 | sub fire_plugin_event { | ||
| 8 | my $orig = shift; | ||
| 9 | my $self = shift; | ||
| 10 | |||
| 11 | # Save the return value | ||
| 12 | my $result = $self->$orig(@_); | ||
| 13 | |||
| 14 | # Fire event that Padre does not implement at the moment | ||
| 15 | $self->{ide}->plugin_manager->plugin_event('editor_changed'); | ||
| 16 | |||
| 17 | # And return the original result | ||
| 18 | return $result; | ||
| 19 | } | ||
| 20 | |||
| 21 | # Hook up to new_document_from_string | ||
| 22 | around 'new_document_from_string' => \&fire_plugin_event; | ||
| 23 | |||
| 24 | # Hook up to on_save_as | ||
| 25 | around 'on_save_as' => \&fire_plugin_event; | ||
| 26 | |||
| 27 | no Moose::Role; | ||
| 28 | 1; |