blib/lib/App/gh/Command/Page.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 69 CC 4 SCAR 16.4
CC
4
Cov
0%
parse_uri
12.0
run
6.0
get_remote
2.0
CRAP 5.2
1 package App::gh::Command::Page;
2 use warnings;
3 use strict;
4 use base qw(App::gh::Command);
5 use App::gh;
6 use App::gh::Utils;
7 use File::Spec;
8  
9 =head1 NAME
10  
11 App::gh::Command::Page - create GitHub gh-page
12  
13 =head1 DESCRIPTION
14  
15 =head1 USAGE
16  
17 =pod
18  
19 command flow:
20  
21 $ git symbolic-ref HEAD refs/heads/gh-pages
22 $ rm .git/index
23 $ git clean -fdx
24 $ git push origin github
25  
26  
27 =cut
28  
29 sub get_remote {
30 my $self = shift;
31 my $config = App::gh->config->current();
32 my %remotes = %{ $config->{remote} };
33 # try to get origin remote
34 return $remotes{origin} || (values( %remotes ))[0];
35 }
36  
37 sub parse_uri {
38 my ($uri) = @_;
39 if ( $uri =~ m{(git|https?)://github.com/(.*?)/(.*?).git} ) {
40 return ($2,$3,$1);
41 } elsif ( $uri =~ m{git\@github.com:(.*?)/(.*?).git} ) {
42 return ($1,$2,'git');
43 }
44 return undef;
45 }
46  
47 sub run {
48 my $self = shift;
49 my $git = App::gh->git;
50 $git->command('symbolic-ref','HEAD','refs/heads/gh-pages');
51 unlink File::Spec->join( $git->wc_path , '.git' , 'index' );
52 $git->command('clean','-fdx');
53  
54 print "Branch gh-pages created\n";
55 print "Please add your index.html page and commit the file.\n";
56 print "Then push gh-pages branch to github remote.\n";
57 print "\n";
58 print "\t\$ git push origin gh-pages\n";
59 print "\n";
60  
61 my $remote = $self->get_remote;
62 die "Remote not found\n." unless $remote;
63 my ($user,$repo,$uri_type) = parse_uri( $remote->{url} );
64  
65 # http://c9s.github.com/App-gh/
66 my $id = App::gh->config->github_id;
67 my $url = sprintf 'http://%s.github.com/%s', $id, $repo;
68 print "Your preview URL: $url\n";
69  
70 print "Reference: http://pages.github.com/\n";
71 }
72  
73  
74 1;