Database/Role/RefReader.pm

filter: Statementstmt 100% 11 / 11 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 100% 2 / 2 totaltotal 100% 18 / 18 SCAR 6.9
CC
2
Cov
100%
ref_names
2.0
BEGIN
1.0
ref_digest
1.0
CRAP 2.0
« Database/DirectoryEntry.pm ↑ Summary Database/Actor.pm »
1 package Git::Database::Role::RefReader;
2 16 $Git::Database::Role::RefReader::VERSION = '0.012';
3 16 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 16 requires
6 'refs',
7 ;
8  
9 # basic implementations
10 sub ref_names {
11 42 ▶ my ( $self, $type ) = @_;
Subroutine ref_names: called CC=2 SCAR=6.9
Pod documented
12 return $type
13 28 ? sort grep m{^refs/\Q$type\E/}, keys %{ $self->refs }
14 42 ▶ : sort keys %{ $self->refs };
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 28 14 42
15 }
16  
17 76 ▶sub ref_digest { $_[0]->refs->{ $_[1] } }
Subroutine ref_digest: called CC=1 SCAR=0.0
Pod documented
18  
19 16 1;
20  
21 __END__
22  
23 =pod
24  
25 =head1 NAME
26  
27 Git::Database::Role::RefReader - Abstract role for Git backends that read references
28  
29 =head1 VERSION
30  
31 version 0.012
32  
33 =head1 SYNOPSIS
34  
35 package MyGitBackend;
36  
37 use Moo;
38 use namespace::clean;
39  
40 with
41 'Git::Database::Role::Backend',
42 'Git::Database::Role::RefReader';
43  
44 # implement the required methods
45 sub refs { ... }
46  
47 =head1 DESCRIPTION
48  
49 A L<backend|Git::Database::Role::Backend> doing the additional
50 Git::Database::Role::RefReader role is capable of reading references
51 from a Git repository and return information about them.
52  
53 =head1 REQUIRED METHODS
54  
55 =head2 refs
56  
57 my $refs = $backend->refs;
58  
59 Return a hash reference mapping all the (fully qualified) refnames in
60 the repository to the corresponding digests (including C<HEAD>).
61  
62 =head1 METHODS
63  
64 =head2 ref_names
65  
66 my @refs = $backend->ref_names;
67 my @heads = $backend->ref_names('heads');
68 my @remotes = $backend->ref_names('remotes');
69  
70 Return the list of refnames in the repository.
71  
72 The optional argument is used to limit the list of returned names to
73 those having the part after C<refs/> in their name equal to it (up to
74 the next C</>).
75  
76 For example, given the following refs:
77  
78 HEAD
79 refs/heads/master
80 refs/remotes/origin/HEAD
81 refs/remotes/origin/master
82 refs/tags/world
83  
84 C<ref_names('heads')> will return C<refs/heads/master>,
85 C<ref_names('head')> will return nothing,
86 C<ref_names('remotes/origin')> will return C<refs/remotes/origin/HEAD>
87 and C<refs/remotes/origin/master>.
88  
89 =head2 ref_digest
90  
91 $backend->ref_digest('refs/heads/master'); # some SHA-1
92  
93 $backend->ref_digest('master'); # undef
94  
95 Return the digest of the given reference, or C<undef>.
96  
97 Note that a fully qualified refname is required. This method does not
98 perform any disambiguation.
99  
100 =head1 AUTHOR
101  
102 Philippe Bruhat (BooK) <book@cpan.org>.
103  
104 =head1 COPYRIGHT
105  
106 Copyright 2016 Philippe Bruhat (BooK), all rights reserved.
107  
108 =head1 LICENSE
109  
110 This program is free software; you can redistribute it and/or modify it
111 under the same terms as Perl itself.
112  
113 =cut
« Database/DirectoryEntry.pm ↑ Summary Database/Actor.pm »