Plagger/Plugin/Summary/AppleScript.pm untested

filter: Statementstmt 0.0% 0 / 22 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 35 CC 2 SCAR 11.0
CC
2
Cov
0%
summarize
6.0
register
2.0
escape
2.0
CRAP 3.0
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; # delete YEN SIGN or BACKSLASH
32 return substr $_[0], 1, length($_[0])-2; # strip quotation
33 }
34  
35 1;
36 __END__