| 1 | 3 | ▶ | use 5.008008; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | package Ask::Zenity; | ||||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | 3 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||
| 8 | 3 | our $VERSION = '0.015'; | |||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 3 | ▶ | use Moo; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | 3 | ▶ | use File::Which qw(which); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | 3 | ▶ | use System::Command; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | 3 | ▶ | use Path::Tiny qw( path ); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | has zenity_path => ( | ||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||
| 18 | 0 | ▶ | default => sub { which( 'zenity' ) || '/usr/bin/zenity' }, | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||
| 19 | 3 | ); | |||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | has system_wrapper => ( | ||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||
| 23 | 0 | ▶ | default => sub { 'System::Command' }, | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 24 | 3 | ); | |||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | 3 | with 'Ask::API'; | |||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | 0 | ▶ | sub is_usable { | ||||||||||||||||||||
|
Subroutine
is_usable: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||
| 29 | 0 | my ( $self ) = @_; | |||||||||||||||||||||
| 30 | 0 | ▶ | return unless !!$ENV{'DISPLAY'}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 31 | 0 | ▶ | return unless -x $self->zenity_path; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 32 | 0 | return 1; | |||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | 9 | ▶ | sub quality { | ||||||||||||||||||||
|
Subroutine
quality: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 36 | 9 | return 40; | |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | 0 | ▶ | sub _optionize { | ||||||||||||||||||||
|
Subroutine
_optionize: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 40 | 0 | my $opt = shift; | |||||||||||||||||||||
| 41 | 0 | $opt =~ s/_/-/g; | |||||||||||||||||||||
| 42 | 0 | return "--$opt"; | |||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||
| 44 | |||||||||||||||||||||||
| 45 | 0 | ▶ | sub _zenity { | ||||||||||||||||||||
|
Subroutine
_zenity: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 46 | 0 | my ( $self, $cmd, %o ) = @_; | |||||||||||||||||||||
| 47 | my $zen = $self->system_wrapper->new( | ||||||||||||||||||||||
| 48 | $self->zenity_path, | ||||||||||||||||||||||
| 49 | _optionize( $cmd ), | ||||||||||||||||||||||
| 50 | 0 | map sprintf( '%s="%s"', _optionize( $_ ), $o{$_} ), keys %o, | |||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||
| 52 | |||||||||||||||||||||||
| 53 | # warn join q[ ], $zen->cmdline; | ||||||||||||||||||||||
| 54 | 0 | return $zen; | |||||||||||||||||||||
| 55 | } #/ sub _zenity | ||||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | 0 | ▶ | sub entry { | ||||||||||||||||||||
|
Subroutine
entry: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 58 | 0 | my $self = shift; | |||||||||||||||||||||
| 59 | 0 | my $text = readline( $self->_zenity( entry => @_ )->stdout ); | |||||||||||||||||||||
| 60 | 0 | chomp $text; | |||||||||||||||||||||
| 61 | 0 | return $text; | |||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | 0 | ▶ | sub info { | ||||||||||||||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||||
| 66 | 0 | $self->_zenity( info => @_ )->close; | |||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||
| 68 | |||||||||||||||||||||||
| 69 | 0 | ▶ | sub warning { | ||||||||||||||||||||
|
Subroutine
warning: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 70 | 0 | my $self = shift; | |||||||||||||||||||||
| 71 | 0 | $self->_zenity( warning => @_ )->close; | |||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||
| 73 | |||||||||||||||||||||||
| 74 | 0 | ▶ | sub error { | ||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 75 | 0 | my $self = shift; | |||||||||||||||||||||
| 76 | 0 | $self->_zenity( error => @_ )->close; | |||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||
| 78 | |||||||||||||||||||||||
| 79 | 0 | ▶ | sub question { | ||||||||||||||||||||
|
Subroutine
question: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||||
| 81 | 0 | my $zen = $self->_zenity( error => @_ ); | |||||||||||||||||||||
| 82 | 0 | $zen->close; | |||||||||||||||||||||
| 83 | 0 | return not $zen->exit; | |||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | 0 | ▶ | sub file_selection { | ||||||||||||||||||||
|
Subroutine
file_selection: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||
| 87 | 0 | my $self = shift; | |||||||||||||||||||||
| 88 | 0 | my $text = readline( $self->_zenity( file_selection => @_ )->stdout ); | |||||||||||||||||||||
| 89 | 0 | chomp $text; | |||||||||||||||||||||
| 90 | 0 | my @files = map path( $_ ), split m#[|]#, $text; | |||||||||||||||||||||
| 91 | 0 | ▶ | @files == 1 ? $files[0] : @files; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | 0 | ▶ | sub single_choice { | ||||||||||||||||||||
|
Subroutine
single_choice: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||
| 95 | 0 | my ( $self, %o ) = @_; | |||||||||||||||||||||
| 96 | 0 | ▶ | $o{title} = 'Single choice' unless exists $o{title}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 97 | 0 | ▶ | $o{text} = 'Choose one.' unless exists $o{text}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 98 | 0 | my ( $c ) = $self->_choice( radiolist => 1, %o ); | |||||||||||||||||||||
| 99 | 0 | return $c; | |||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||
| 101 | |||||||||||||||||||||||
| 102 | 0 | ▶ | sub multiple_choice { | ||||||||||||||||||||
|
Subroutine
multiple_choice: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||
| 103 | 0 | my ( $self, %o ) = @_; | |||||||||||||||||||||
| 104 | 0 | ▶ | $o{title} = 'Multiple choice' unless exists $o{title}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 105 | 0 | ▶ | $o{text} = '' unless exists $o{text}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 106 | 0 | return $self->_choice( multiple => 1, checklist => 1, %o ); | |||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | 0 | ▶ | sub _choice { | ||||||||||||||||||||
|
Subroutine
_choice: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||
| 110 | 0 | my ( $self, %o ) = @_; | |||||||||||||||||||||
| 111 | 0 | my $subsequent; | |||||||||||||||||||||
| 112 | my $zen = $self->system_wrapper->new( | ||||||||||||||||||||||
| 113 | $self->zenity_path, | ||||||||||||||||||||||
| 114 | '--list', | ||||||||||||||||||||||
| 115 | ( $o{radiolist} ? '--radiolist' : () ), | ||||||||||||||||||||||
| 116 | ( $o{checklist} ? '--checklist' : () ), | ||||||||||||||||||||||
| 117 | ( $o{multiple} ? '--multiple' : () ), | ||||||||||||||||||||||
| 118 | '--column=Select', | ||||||||||||||||||||||
| 119 | '--column=Code', | ||||||||||||||||||||||
| 120 | '--column=Choice', | ||||||||||||||||||||||
| 121 | '--hide-column=2', | ||||||||||||||||||||||
| 122 | '--text', $o{text}, | ||||||||||||||||||||||
| 123 | 0 | ▶ | map { ( $subsequent++ ? 'FALSE' : 'TRUE' ), @$_ } @{ $o{choices} }, | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||
| 125 | 0 | chomp( my $line = readline( $zen->stdout ) ); | |||||||||||||||||||||
| 126 | 0 | split m{\|}, $line; | |||||||||||||||||||||
| 127 | } #/ sub _choice | ||||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | 3 | 1; | |||||||||||||||||||||
| 130 | |||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||