1 |
package Frey::Editor; |
2 |
use Moose; |
3 |
|
4 |
=head1 DESCRIPTION |
5 |
|
6 |
Support for local editor invocation from web |
7 |
|
8 |
<a href="/editor+$path+$line" target="editor">$class</a> |
9 |
|
10 |
=head2 url |
11 |
|
12 |
$path =~ $editor->url_regex |
13 |
|
14 |
=cut |
15 |
|
16 |
sub url_regex { qr{/editor\+?(.+?)\+(\d+)} } |
17 |
|
18 |
=head2 command |
19 |
|
20 |
my $system = $editor->command( $path ); |
21 |
|
22 |
=cut |
23 |
|
24 |
sub command { |
25 |
my ( $self, $url ) = @_; |
26 |
$url =~ url_regex; |
27 |
my $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi'; |
28 |
# FIXME SECURITY path verification for $1 |
29 |
my $cmd = "$editor $1 +$2"; |
30 |
warn "# $url -> system $cmd"; |
31 |
return $cmd; |
32 |
} |
33 |
|
34 |
1; |