| 1 | #!perl | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 4 | ▶ | use Getopt::Long qw( GetOptions ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 4 | use Open::This qw( | |||||||||||||||||||
| 8 | editor_args_from_parsed_text | ||||||||||||||||||||
| 9 | maybe_get_url_from_parsed_text | ||||||||||||||||||||
| 10 | parse_text | ||||||||||||||||||||
| 11 | 4 | ▶ | ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 4 | ▶ | use Path::Tiny qw( path ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 4 | ▶ | use Pod::Usage qw( pod2usage ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 4 | ▶ | pod2usage("Error: missing argument\n") unless @ARGV; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 4 | my $browse; | |||||||||||||||||||
| 18 | my $editor; | ||||||||||||||||||||
| 19 | 4 | my $print; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 4 | GetOptions( | |||||||||||||||||||
| 22 | 'browse|b' => \$browse, | ||||||||||||||||||||
| 23 | 'editor|e=s' => \$editor, | ||||||||||||||||||||
| 24 | 'print|p' => \$print, | ||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 4 | my $parsed = parse_text(@ARGV); | |||||||||||||||||||
| 28 | 4 | ▶ | if ( !$parsed ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 0 | print "Could not locate file\n"; | |||||||||||||||||||
| 30 | 0 | exit(1); | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 4 | ▶ | if ($browse) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 0 | my $url = maybe_get_url_from_parsed_text($parsed); | |||||||||||||||||||
| 35 | 0 | ▶ | if ( !exists $parsed->{remote_file_url} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 0 | print "Could not find remote repository\n"; | |||||||||||||||||||
| 37 | 0 | exit(1); | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | # A relative path should be inside our repository | ||||||||||||||||||||
| 41 | 0 | ▶ | if ( path( $parsed->{remote_file_url} )->is_relative ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | require Browser::Open; | |||||||||||||||||||
| 43 | 0 | Browser::Open::open_browser( $parsed->{remote_file_url} ); | |||||||||||||||||||
| 44 | 0 | exit(0); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 0 | return undef; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 4 | ▶ | local $ENV{EDITOR} = $editor || $ENV{EDITOR}; | ||||||||||||||||||
|
Condition33%1/3
$editor || $ENV{'EDITOR'}
MC/DC0%0/2
$editor || $ENV{'EDITOR'}
$editor
$ENV{'EDITOR'}
Truth table33%1/3
A || B
A= $editorB= $ENV{'EDITOR'}
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 4 | my @editor_args = editor_args_from_parsed_text($parsed); | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 4 | ▶ | if ($print) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 4 | print STDOUT join( ' ', @editor_args ), "\n"; | |||||||||||||||||||
| 55 | 4 | exit(0); | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | $ENV{EDITOR} | ||||||||||||||||||||
| 59 | ? exec $ENV{EDITOR}, @editor_args | ||||||||||||||||||||
| 60 | 0 | ▶ | : die('Please set your $EDITOR env var or use the --editor arg'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | # ABSTRACT: parse text and (hopefully) open an editor with the correct arguments | ||||||||||||||||||||
| 63 | # PODNAME: ot | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||