blib/lib/Dist/Zilla/Role/Git/Repo.pm

filter: Statementstmt 100% 33 / 33 Branchbran 50.0% 1 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 91.8% 45 / 49 CC 3 SCAR 3.4
CC
3
Cov
95%
git
2.0
_build_current_git_branch
2.0
BEGIN
1.0
CRAP 1.4
« blib/lib/Dist/Zilla/Role/Git/DirtyFiles.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/Git.pm »
1 #
2 # This file is part of Dist-Zilla-Plugin-Git
3 #
4 # This software is copyright (c) 2009 by Jerome Quelin.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 package Dist::Zilla::Role::Git::Repo;
10 # ABSTRACT: Provide repository information for Git plugins
11  
12 19 our $VERSION = '2.052';
13  
14 19 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 19 ▶use Types::Standard qw(Str Maybe);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 19 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 19 has repo_root => (
19 is => 'ro',
20 isa => Str,
21 lazy => 1,
22 builder => '_build_repo_root',
23 );
24  
25 sub _build_repo_root
26 53 ▶{
Subroutine _build_repo_root: called CC=1 SCAR=0.0
27 53 my $self = shift;
28 53 $self->zilla->root->stringify;
29 }
30  
31 #pod =method current_git_branch
32 #pod
33 #pod $branch = $plugin->current_git_branch;
34 #pod
35 #pod The current branch in the repository, or C<undef> if the repository
36 #pod has a detached HEAD. Note: This value is cached; it will not
37 #pod be updated if the branch is changed during the run.
38 #pod
39 #pod =cut
40  
41 19 has current_git_branch => (
42 is => 'ro',
43 isa => Maybe[Str],
44 lazy => 1,
45 builder => '_build_current_git_branch',
46 init_arg => undef, # Not configurable
47 );
48  
49 sub _build_current_git_branch
50 2 ▶{
Subroutine _build_current_git_branch: called CC=2 SCAR=7.0
51 2 my $self = shift;
52  
53 # Git 1.7+ allows "rev-parse --abbrev-ref HEAD", but we want to support 1.5.4
54 2 my ($branch) = $self->git->RUN(qw(symbolic-ref -q HEAD));
55  
56 19 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
57 2 ▶ undef $branch unless $branch =~ s!^refs/heads/!!;
Branch: 1 branch
BranchTrueFalseTotal
unless $branch =~ s[^refs/heads/][] 0 2 2
58  
59 2 $branch;
60 } # end _build_current_git_branch
61  
62 #pod =method git
63 #pod
64 #pod $git = $plugin->git;
65 #pod
66 #pod This method returns a Git::Wrapper object for the C<repo_root>
67 #pod directory, constructing one if necessary. The object is shared
68 #pod between all plugins that consume this role (if they have the same
69 #pod C<repo_root>).
70 #pod
71 #pod =cut
72  
73 19 my %cached_wrapper;
74  
75 around dump_config => sub
76 34 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
77 34 my $orig = shift;
78 34 my $self = shift;
79  
80 34 my $config = $self->$orig;
81  
82 34 $config->{+__PACKAGE__} = {
83 repo_root => $self->repo_root,
84 git_version => $self->git->version,
85 };
86  
87 34 return $config;
88 19 };
89  
90 143 ▶sub git {
Subroutine git: called CC=2 SCAR=7.0
Pod documented
91 143 my $root = shift->repo_root;
92  
93 143 ▶ $cached_wrapper{$root} ||= do {
Condition66%2/3
$cached_wrapper{$root} ||= do { require Git::Wrapper; "Git::Wrapper"->new($root) }
l!l&&r!l&&!r
99440
MC/DC0%0/2
$cached_wrapper{$root} ||= do { require Git::Wrapper; "Git::Wrapper"->new($root) }
$cached_wrapper{$root} do { require Git::Wrapper; "Git::Wrapper"->new($root) }
Truth table66%2/3
A ||= B
A= $cached_wrapper{$root}B= do { require Git::Wrapper; "Git::Wrapper"->new($root) }
ABresult
1X1
011
000
94 44 require Git::Wrapper;
95 44 Git::Wrapper->new( $root );
96 };
97 }
98  
99 19 1;
100  
101 __END__
« blib/lib/Dist/Zilla/Role/Git/DirtyFiles.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/Git.pm »