| Line | |
|---|
| 1 |
package Plagger::Plugin::Summary::AppleScript; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin ); |
|---|
| 4 |
|
|---|
| 5 |
use Mac::AppleScript qw(RunAppleScript); |
|---|
| 6 |
|
|---|
| 7 |
sub register { |
|---|
| 8 |
my($self, $context) = @_; |
|---|
| 9 |
$context->register_hook( |
|---|
| 10 |
$self, |
|---|
| 11 |
'summarizer.summarize' => \&summarize, |
|---|
| 12 |
); |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
sub summarize { |
|---|
| 16 |
my($self, $context, $args) = @_; |
|---|
| 17 |
|
|---|
| 18 |
my $result = |
|---|
| 19 |
RunAppleScript(qq{summarize "@{[escape($args->{text}->plaintext)]}" in 1}); |
|---|
| 20 |
if ($@) { |
|---|
| 21 |
$context->log(error => "AppleScript error: $@"); |
|---|
| 22 |
return; |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
return fixquote($result); |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
sub escape { $_[0] =~ s/"/\\"/mg; $_[0] } |
|---|
| 29 |
|
|---|
| 30 |
sub fixquote { |
|---|
| 31 |
$_[0] =~ s/(?:\xC2\xA5|\\)"/"/mg; |
|---|
| 32 |
return substr $_[0], 1, length($_[0])-2; |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
1; |
|---|
| 36 |
__END__ |
|---|
| 37 |
|
|---|
| 38 |
=head1 NAME |
|---|
| 39 |
|
|---|
| 40 |
Plagger::Plugin::Summary::AppleScript - use AppleScript summarize Command |
|---|
| 41 |
|
|---|
| 42 |
=head1 SYNOPSIS |
|---|
| 43 |
|
|---|
| 44 |
- module: Summary::AppleScript |
|---|
| 45 |
|
|---|
| 46 |
=head1 DESCRIPTION |
|---|
| 47 |
|
|---|
| 48 |
This plugin uses AppleScript summarize command to generate summary off of |
|---|
| 49 |
plaintext-ized body. |
|---|
| 50 |
|
|---|
| 51 |
=head1 AUTHOR |
|---|
| 52 |
|
|---|
| 53 |
Masafumi Otsune |
|---|
| 54 |
|
|---|
| 55 |
=head1 SEE ALSO |
|---|
| 56 |
|
|---|
| 57 |
L<Plagger>, L<Mac::AppleScript> |
|---|
| 58 |
|
|---|
| 59 |
=cut |
|---|