| 1 | # ABSTRACT: Utility class for authoring commit messages | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | package Pinto::Editor; | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 64 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 64 | ▶ | use File::Temp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 64 | ▶ | use Pinto::Editor::Edit; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 64 | our $VERSION = '0.14'; # VERSION | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 0 | ▶ | sub EDITOR { | ||||||||||||||||||
|
Subroutine
EDITOR: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 16 | 0 | ▶ | return $ENV{VISUAL} || $ENV{EDITOR}; | ||||||||||||||||||
|
Condition0%0/3
$ENV{'VISUAL'} || $ENV{'EDITOR'}
MC/DC0%0/2
$ENV{'VISUAL'} || $ENV{'EDITOR'}
$ENV{'VISUAL'}
$ENV{'EDITOR'}
Truth table0%0/3
A || B
A= $ENV{'VISUAL'}B= $ENV{'EDITOR'}
| |||||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 64 | our $__singleton__; | |||||||||||||||||||
| 22 | 0 | ▶ | sub __singleton__ { | ||||||||||||||||||
|
Subroutine
__singleton__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 23 | 0 | ▶ | return $__singleton__ ||=__PACKAGE__->new; | ||||||||||||||||||
|
Condition0%0/3
$Pinto::Editor::__singleton__ ||= __PACKAGE__->new
MC/DC0%0/2
$Pinto::Editor::__singleton__ ||= __PACKAGE__->new
$Pinto::Editor::__singleton__
__PACKAGE__->new
Truth table0%0/3
A ||= B
A= $Pinto::Editor::__singleton__B= __PACKAGE__->new
| |||||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | sub edit_file { | ||||||||||||||||||
|
Subroutine
edit_file: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 29 | 0 | my $self = shift; | |||||||||||||||||||
| 30 | 0 | my $file = shift; | |||||||||||||||||||
| 31 | 0 | ▶ | die "*** Missing editor (No \$VISUAL or \$EDITOR)\n" unless my $editor = $self->EDITOR; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 0 | my $rc = system $editor, $file; | |||||||||||||||||||
| 33 | 0 | ▶ | unless ( $rc == 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 0 | my ($exit_value, $signal, $core_dump); | |||||||||||||||||||
| 35 | 0 | $exit_value = $? >> 8; | |||||||||||||||||||
| 36 | 0 | $signal = $? & 127; | |||||||||||||||||||
| 37 | 0 | $core_dump = $? & 128; | |||||||||||||||||||
| 38 | 0 | die "Error during edit ($editor): exit value($exit_value), signal($signal), core_dump($core_dump): $!"; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | sub edit { | ||||||||||||||||||
|
Subroutine
edit: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||||||||||
| 46 | 0 | ▶ | $self = $self->__singleton__ unless blessed $self; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 0 | my %given = @_; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | my $document = delete $given{document}; | |||||||||||||||||||
| 50 | 0 | ▶ | $document = '' unless defined $document; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | my $file = delete $given{file}; | |||||||||||||||||||
| 53 | 0 | ▶ | $file = $self->tmp unless defined $file; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | my $edit = Pinto::Editor::Edit->new( | |||||||||||||||||||
| 56 | editor => $self, | ||||||||||||||||||||
| 57 | file => $file, | ||||||||||||||||||||
| 58 | document => $document, | ||||||||||||||||||||
| 59 | %given, # process, split, ... | ||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | return $edit->edit; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 0 | ▶ | sub tmp { return File::Temp->new( unlink => 1 ) } | ||||||||||||||||||
|
Subroutine
tmp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 70 | 64 | 1; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =pod | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =encoding UTF-8 | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =for :stopwords Jeffrey Ryan Thalhammer | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | =head1 NAME | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | Pinto::Editor - Utility class for authoring commit messages | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | =head1 VERSION | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | version 0.14 | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =head1 DESCRIPTION | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | This is a forked version of L<Term::EditorEdit> which does not use the deprecated | ||||||||||||||||||||
| 89 | module L<Any::Moose>. My thanks to Robert Krimen for authoring the original. | ||||||||||||||||||||
| 90 | No user-servicable parts in here. | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | =head1 AUTHOR | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | Jeffrey Ryan Thalhammer <jeff@stratopan.com> | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer. | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 101 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | =cut | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||