| 1 | package Git::Database::Object::Tree; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 20 | $Git::Database::Object::Tree::VERSION = '0.012'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 20 | with 'Git::Database::Role::Object'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use Git::Database::DirectoryEntry; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 945 | ▶ | sub kind {'tree'} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kind: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 20 | has directory_entries => ( | |||||||||||||||||||||||||||||||||||||||||
| 13 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 15 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | builder => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 610 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 610 | ▶ | die "One of 'digest' or 'content' or 'directory_entries' is required" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->has_digest or $self->has_content or $self->has_directory_entries
$self->has_digest or $self->has_content
MC/DC100%3/3
$self->has_digest or $self->has_content or $self->has_directory_entries
$self->has_digest
$self->has_content
$self->has_directory_entries
Truth table100%4/4
A or B or C
A= $self->has_digestB= $self->has_contentC= $self->has_directory_entries
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | if !$self->has_digest | ||||||||||||||||||||||||||||||||||||||||||
| 25 | && !$self->has_content | ||||||||||||||||||||||||||||||||||||||||||
| 26 | && !$self->has_directory_entries; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # sort directory entries | ||||||||||||||||||||||||||||||||||||||||||
| 29 | $self->_set_directory_entries( | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 120 | [ sort { $a->filename cmp $b->filename } | |||||||||||||||||||||||||||||||||||||||||
| 31 | 603 | ▶ | @{ $self->directory_entries } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ) if $self->has_directory_entries; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | sub _build_content { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 298 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_content: called CC=4 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 298 | ▶ | if ( !$self->has_directory_entries ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 98 | my $attr = $self->_get_object_attributes(); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 84 | ▶ | return $attr->{content} if exists $attr->{content}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ( exists $attr->{directory_entries} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $self->_set_directory_entries( $attr->{directory_entries} ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | die "Can't build content from these attributes: " | |||||||||||||||||||||||||||||||||||||||||
| 48 | . join( ', ', sort keys %$attr ); | ||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 200 | return join '', map $_->as_content, @{ $self->directory_entries }; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | # assumes content is set | ||||||||||||||||||||||||||||||||||||||||||
| 56 | sub _build_directory_entries { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 239 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_directory_entries: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 239 | ▶ | if ( !$self->has_content ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 35 | my $attr = $self->_get_object_attributes(); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 28 | ▶ | return $attr->{directory_entries} if exists $attr->{directory_entries}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 28 | ▶ | if ( exists $attr->{content} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 28 | $self->_set_content( $attr->{content} ); | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | die "Can't build content from these attributes: " | |||||||||||||||||||||||||||||||||||||||||
| 68 | . join( ', ', sort keys %$attr ); | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 232 | my $content = $self->content; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 232 | ▶ | return [] unless $content; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 208 | my @directory_entries; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 208 | ▶ | while ($content) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 364 | my $space_index = index( $content, ' ' ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 364 | my $mode = substr( $content, 0, $space_index ); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 364 | $content = substr( $content, $space_index + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 80 | 364 | my $null_index = index( $content, "\0" ); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 364 | my $filename = substr( $content, 0, $null_index ); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 364 | $content = substr( $content, $null_index + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 364 | my $digest = unpack( 'H*', substr( $content, 0, 20 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 84 | 364 | $content = substr( $content, 20 ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 364 | push @directory_entries, | |||||||||||||||||||||||||||||||||||||||||
| 86 | Git::Database::DirectoryEntry->new( | ||||||||||||||||||||||||||||||||||||||||||
| 87 | mode => $mode, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | filename => $filename, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | digest => $digest, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 208 | return \@directory_entries; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | sub as_string { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 244 | ▶ | return join '', map $_->as_string, @{ $_[0]->directory_entries }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | =for Pod::Coverage | ||||||||||||||||||||||||||||||||||||||||||
| 104 | BUILD | ||||||||||||||||||||||||||||||||||||||||||
| 105 | has_directory_entries | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | Git::Database::Object::Tree - A tree object in the Git object database | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | version 0.012 | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | my $r = Git::Database->new(); # current Git repository | ||||||||||||||||||||||||||||||||||||||||||
| 118 | my $tree = $r->get_object('b52168'); # abbreviated digest | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | # attributes | ||||||||||||||||||||||||||||||||||||||||||
| 121 | $tree->kind; # tree | ||||||||||||||||||||||||||||||||||||||||||
| 122 | $tree->digest; # b52168be5ea341e918a9cbbb76012375170a439f | ||||||||||||||||||||||||||||||||||||||||||
| 123 | ...; # etc., see below | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | Git::Database::Object::Tree represents a C<tree> object | ||||||||||||||||||||||||||||||||||||||||||
| 128 | obtained via L<Git::Database> from a Git object database. | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | All attributes have a predicate method. | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | =head2 kind | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | The object kind: C<tree>. | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | =head2 digest | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | The SHA-1 digest of the tree object. | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | =head2 content | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | The object's actual content. | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | =head2 size | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | The size (in bytes) of the object content. | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | =head2 directory_entries | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | An array reference containing a list of L<Git::Database::DirectoryEntry> | ||||||||||||||||||||||||||||||||||||||||||
| 153 | objects representing the content of the tree. | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | =head2 new() | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | Create a new Git::Object::Database::Commit object. | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | One (and only one) of the C<content> or C<directory_entries> arguments | ||||||||||||||||||||||||||||||||||||||||||
| 162 | is required. | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | C<directory_entires> is an array reference containing a list of | ||||||||||||||||||||||||||||||||||||||||||
| 165 | L<Git::Database::DirectoryEntry> objects representing the content | ||||||||||||||||||||||||||||||||||||||||||
| 166 | of the tree. | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | =head2 as_string() | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | The content of the tree object, in the format returned by C<git ls-tree>. | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | L<Git::Database>, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | L<Git::Database::Role::Object>. | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | Philippe Bruhat (BooK) <book@cpan.org>. | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | Copyright 2013-2016 Philippe Bruhat (BooK), all rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||
| 188 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | =cut | ||||||||||||||||||||||||||||||||||||||||||