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