| 1 | package Git::Database::DirectoryEntry; | ||||||||||
| 2 | 22 | $Git::Database::DirectoryEntry::VERSION = '0.012'; | |||||||||
| 3 | 22 | ▶ | use Sub::Quote; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 22 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 22 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # Git only uses the following (octal) modes: | ||||||||||
| 9 | # - 040000 for subdirectory (tree) | ||||||||||
| 10 | # - 100644 for file (blob) | ||||||||||
| 11 | # - 100755 for executable (blob) | ||||||||||
| 12 | # - 120000 for a blob that specifies the path of a symlink | ||||||||||
| 13 | # - 160000 for submodule (commit) | ||||||||||
| 14 | # | ||||||||||
| 15 | # See also: cache.h in git.git | ||||||||||
| 16 | 22 | has mode => ( | |||||||||
| 17 | is => 'ro', | ||||||||||
| 18 | required => 1, | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 22 | has filename => ( | |||||||||
| 22 | is => 'ro', | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 22 | has digest => ( | |||||||||
| 26 | is => 'ro', | ||||||||||
| 27 | isa => quote_sub( | ||||||||||
| 28 | q{ die "Not a SHA-1 digest" unless $_[0] =~ /^[0-9a-f]{40}/; }), | ||||||||||
| 29 | required => 1, | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | sub as_content { | ||||||||||
| 33 | 285 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
as_content: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 34 | return | ||||||||||
| 35 | 285 | $self->mode . ' ' | |||||||||
| 36 | . $self->filename . "\0" | ||||||||||
| 37 | . pack( 'H*', $self->digest ); | ||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | sub as_string { | ||||||||||
| 41 | 376 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
as_string: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 42 | 376 | my $mode = oct( '0' . $self->mode ); | |||||||||
| 43 | 376 | ▶ | return sprintf "%06o %s %s\t%s\n", $mode, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | $mode & 0100000 ? 'blob' : 'tree', | ||||||||||
| 45 | $self->digest, $self->filename; | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | # some helper methods | ||||||||||
| 49 | 10 | ▶ | sub is_tree { !( oct( '0' . $_[0]->mode ) & 0100000 ) } | ||||||||
|
Subroutine
is_tree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 50 | 5 | ▶ | sub is_blob { !!( oct( '0' . $_[0]->mode ) & 0100000 ) } | ||||||||
|
Subroutine
is_blob: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 51 | 5 | ▶ | sub is_executable { !!( oct( '0' . $_[0]->mode ) & 0100 ) } | ||||||||
|
Subroutine
is_executable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 52 | 5 | ▶ | sub is_link { $_[0]->mode eq '120000' } | ||||||||
|
Subroutine
is_link: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 53 | 5 | ▶ | sub is_submodule { $_[0]->mode eq '160000' } | ||||||||
|
Subroutine
is_submodule: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 54 | |||||||||||
| 55 | 22 | 1; | |||||||||
| 56 | |||||||||||
| 57 | __END__ | ||||||||||
| 58 | |||||||||||
| 59 | =pod | ||||||||||
| 60 | |||||||||||
| 61 | =head1 NAME | ||||||||||
| 62 | |||||||||||
| 63 | Git::Database::DirectoryEntry - A directory entry in Git | ||||||||||
| 64 | |||||||||||
| 65 | =head1 VERSION | ||||||||||
| 66 | |||||||||||
| 67 | version 0.012 | ||||||||||
| 68 | |||||||||||
| 69 | =head1 SYNOPSIS | ||||||||||
| 70 | |||||||||||
| 71 | my $hello = Git::Database::DirectoryEntry->new( | ||||||||||
| 72 | mode => '100644', | ||||||||||
| 73 | filename => 'hello', | ||||||||||
| 74 | digest => 'b6fc4c620b67d95f953a5c1c1230aaab5db5a1b0' | ||||||||||
| 75 | ); | ||||||||||
| 76 | |||||||||||
| 77 | my $tree = Git::Database::Object::Tree->new( directory_entries => [$hello] ); | ||||||||||
| 78 | |||||||||||
| 79 | =head1 DESCRIPTION | ||||||||||
| 80 | |||||||||||
| 81 | Git::Database::DirectoryEntry represents a directory entry in a C<tree> | ||||||||||
| 82 | object obtained via L<Git::Database> from a Git object database. | ||||||||||
| 83 | |||||||||||
| 84 | =head1 ATTRIBUTES | ||||||||||
| 85 | |||||||||||
| 86 | =head2 mode | ||||||||||
| 87 | |||||||||||
| 88 | The mode of the directory entry, as a string (octal representation): | ||||||||||
| 89 | |||||||||||
| 90 | =over 4 | ||||||||||
| 91 | |||||||||||
| 92 | =item C<040000> | ||||||||||
| 93 | |||||||||||
| 94 | a subdirectory (tree) | ||||||||||
| 95 | |||||||||||
| 96 | =item C<100644> | ||||||||||
| 97 | |||||||||||
| 98 | a file (blob) | ||||||||||
| 99 | |||||||||||
| 100 | =item C<100755> | ||||||||||
| 101 | |||||||||||
| 102 | an executable file for executable (blob) | ||||||||||
| 103 | |||||||||||
| 104 | =item C<120000> | ||||||||||
| 105 | |||||||||||
| 106 | a symbolic link (the blob contains the path to the target file) | ||||||||||
| 107 | |||||||||||
| 108 | =item C<160000> | ||||||||||
| 109 | |||||||||||
| 110 | a submodule (commit) | ||||||||||
| 111 | |||||||||||
| 112 | =back | ||||||||||
| 113 | |||||||||||
| 114 | =head2 digest | ||||||||||
| 115 | |||||||||||
| 116 | The 40 character digest of the Git object pointed by the directory entry. | ||||||||||
| 117 | |||||||||||
| 118 | =head2 filename | ||||||||||
| 119 | |||||||||||
| 120 | The name of the directory entry. | ||||||||||
| 121 | |||||||||||
| 122 | =head1 METHODS | ||||||||||
| 123 | |||||||||||
| 124 | =head2 as_content | ||||||||||
| 125 | |||||||||||
| 126 | Return a string representing the directory entry in the format used | ||||||||||
| 127 | for the content of tree object. | ||||||||||
| 128 | |||||||||||
| 129 | =head2 as_string | ||||||||||
| 130 | |||||||||||
| 131 | Return a string representing the directory entry in the same format as | ||||||||||
| 132 | C<git ls-tree>. | ||||||||||
| 133 | |||||||||||
| 134 | =head2 is_tree | ||||||||||
| 135 | |||||||||||
| 136 | Return a boolean value indicating whether the directory entry points to a | ||||||||||
| 137 | tree object. | ||||||||||
| 138 | |||||||||||
| 139 | =head2 is_blob | ||||||||||
| 140 | |||||||||||
| 141 | Return a boolean value indicating whether the directory entry points to a | ||||||||||
| 142 | blob object. | ||||||||||
| 143 | |||||||||||
| 144 | =head2 is_executable | ||||||||||
| 145 | |||||||||||
| 146 | Return a boolean value indicating whether the directory entry has the | ||||||||||
| 147 | executable switched. | ||||||||||
| 148 | |||||||||||
| 149 | =head2 is_link | ||||||||||
| 150 | |||||||||||
| 151 | Return a boolean value indicating whether the directory entry points to a | ||||||||||
| 152 | a link. Note: a link is a blob. | ||||||||||
| 153 | |||||||||||
| 154 | =head2 is_submodule | ||||||||||
| 155 | |||||||||||
| 156 | Return a boolean value indicating whether the directory entry points to a | ||||||||||
| 157 | a submodule. Note: a submodule is a blob. | ||||||||||
| 158 | |||||||||||
| 159 | =head1 SEE ALSO | ||||||||||
| 160 | |||||||||||
| 161 | L<Git::Database>, | ||||||||||
| 162 | L<Git::Database::Object::Tree>. | ||||||||||
| 163 | |||||||||||
| 164 | =head1 AUTHOR | ||||||||||
| 165 | |||||||||||
| 166 | Philippe Bruhat (BooK) <book@cpan.org>. | ||||||||||
| 167 | |||||||||||
| 168 | =head1 COPYRIGHT | ||||||||||
| 169 | |||||||||||
| 170 | Copyright 2013-2016 Philippe Bruhat (BooK), all rights reserved. | ||||||||||
| 171 | |||||||||||
| 172 | =head1 LICENSE | ||||||||||
| 173 | |||||||||||
| 174 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 175 | under the same terms as Perl itself. | ||||||||||
| 176 | |||||||||||
| 177 | =cut | ||||||||||