| 1 | package App::gist; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | $App::gist::VERSION = '0.16'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use base qw(App::Cmd::Simple); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Pithub::Gists; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Class::Load qw(try_load_class); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | package App::gist::Auth; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | $App::gist::Auth::VERSION = '0.16'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Pithub::Base; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | around _request_for => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my ($orig, $self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my $req = $self -> $orig(@args); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my ($login, $passwd) = App::gist::_get_credentials(); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | $req -> headers -> remove_header('Authorization'); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | $req -> headers -> authorization_basic($login, $passwd); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | return $req; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | 'Moo::Role' -> apply_roles_to_package( | |||||||||||||||||||||||||||||||||||||||||
| 31 | 'Pithub::Base', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 'App::gist::Auth' | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | App::gist - Gist command-line tool | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | version 0.16 | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | $ gist script.pl | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opt_spec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ['description|d=s', 'set the description for the gist' ], | |||||||||||||||||||||||||||||||||||||||||
| 53 | ['name|n=s', 'specify the name of the file' ], | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ['update|u=s', 'update the given gist with the given file'], | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ['private|p', 'create a private gist' ], | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ['web|w', 'only output the web url' ] | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub validate_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_args: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $self -> usage_error("Too few arguments.") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
%$opt or @$args or not -t STDIN
%$opt or @$args
MC/DC0%0/3
%$opt or @$args or not -t STDIN
%$opt
@$args
not -t STDIN
Truth table0%0/4
A or B or not(C)
A= %$optB= @$argsC= not -t STDIN
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | unless %$opt || @$args || ! -t STDIN; | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $id = $opt -> {'update'}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $file = $args -> [0]; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $description = $opt -> {'description'}; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $public = $opt -> {'private'} ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my $web = $opt -> {'web'} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my ($name, $data); | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | open my $fh, '<', $file or die "Err: Enter a valid file name.\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $data = join('', <$fh>); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $name = basename($file); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $name = $opt -> {'name'} || 'gistfile.txt'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt->{'name'} || 'gistfile.txt'
MC/DC0%0/1
$opt->{'name'} || 'gistfile.txt'
$opt->{'name'}
Truth table0%0/2
A
A= $opt->{'name'}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $data = join('', <STDIN>); | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $gist = Pithub::Gists -> new; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my $info = $id ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | _edit_gist($gist, $id, $name, $data) : | ||||||||||||||||||||||||||||||||||||||||||
| 93 | _create_gist($gist, $name, $data, $description, $public); | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | die "Err: " . $info -> content -> {'message'} . ".\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | unless $info -> success; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $gist_id = $info -> content -> {'id'}; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $html_url = $info -> content -> {'html_url'}; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $pull_url = $info -> content -> {'git_pull_url'}; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $push_url = $info -> content -> {'git_push_url'}; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($web) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | print "$html_url\n"; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | print "Gist '$gist_id' successfully created/updated.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | print "Web URL: $html_url\n"; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | print "Public Clone URL: $pull_url\n" if $public; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | print "Private Clone URL: $push_url\n"; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub _create_gist { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_gist: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my ($gist, $name, $data, $description, $public) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | return $gist -> create(data => { | |||||||||||||||||||||||||||||||||||||||||
| 117 | description => $description, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | public => $public, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | files => { | ||||||||||||||||||||||||||||||||||||||||||
| 120 | $name => { content => $data } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub _edit_gist { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_edit_gist: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my ($gist, $id, $name, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $info = $gist -> get(gist_id => $id); | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | die "Err: " . $info -> content -> {'message'} . ".\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | unless $info -> success; | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | return $gist -> update( | ||||||||||||||||||||||||||||||||||||||||||
| 134 | gist_id => $id, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | data => { | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | description => $info -> content -> {'description'}, | |||||||||||||||||||||||||||||||||||||||||
| 137 | files => { | ||||||||||||||||||||||||||||||||||||||||||
| 138 | $name => { content => $data } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub _get_credentials { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_credentials: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my ($login, $pass, $token); | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | my %identity = Config::Identity::GitHub -> load | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | if try_load_class('Config::Identity::GitHub'); | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if (%identity) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $login = $identity{'login'}; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $login = `git config github.user`; chomp $login; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if (!$login) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | my $error = %identity ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | "Err: missing value 'user' in ~/.github" : | ||||||||||||||||||||||||||||||||||||||||||
| 159 | "Err: Missing value 'github.user' in git config"; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | die "$error.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if (%identity) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $token = $identity{'token'}; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $pass = $identity{'password'}; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $token = `git config github.token`; chomp $token; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $pass = `git config github.password`; chomp $pass; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ($token) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | die "Err: Login with GitHub token is deprecated.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } elsif (!$pass) { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | require Term::ReadKey; | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | print STDERR "Enter password for '$login': "; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | Term::ReadKey::ReadMode('noecho'); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | chop($pass = <STDIN>); | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | Term::ReadKey::ReadMode('normal'); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | return ($login, $pass); | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | Alessandro Ghedini <alexbio@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | Copyright 2011 Alessandro Ghedini. | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||
| 196 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||||||||||||||||
| 197 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | 1; # End of App::gist | |||||||||||||||||||||||||||||||||||||||||