| 1 | package Cogit::Object::Tree; | ||||||||||
| 2 | 4 | $Cogit::Object::Tree::VERSION = '0.001001'; | |||||||||
| 3 | 4 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use Cogit::DirectoryEntry; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use MooX::Types::MooseLike::Base 'ArrayRef', 'InstanceOf'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 4 | extends 'Cogit::Object'; | |||||||||
| 9 | |||||||||||
| 10 | 4 | ▶ | has '+kind' => ( default => sub { 'tree' } ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 4 | has directory_entries => ( | |||||||||
| 13 | is => 'rw', | ||||||||||
| 14 | isa => ArrayRef[InstanceOf['Cogit::DirectoryEntry']], | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | 4 | ▶ | sub _build_content { | ||||||||
|
Subroutine
_build_content: called CC=2 SCAR=6.9
| |||||||||||
| 18 | 4 | my $self = shift; | |||||||||
| 19 | 4 | my $content; | |||||||||
| 20 | 4 | for my $de ( @{$self->directory_entries} ) { | |||||||||
| 21 | 8 | $content | |||||||||
| 22 | .= $de->mode . ' ' | ||||||||||
| 23 | . $de->filename . "\0" | ||||||||||
| 24 | . pack( 'H*', $de->sha1 ); | ||||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 4 | return $content; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 35 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 31 | 35 | my $self = shift; | |||||||||
| 32 | 35 | my $content = $self->content; | |||||||||
| 33 | 35 | ▶ | return unless $content; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 35 | my @directory_entries; | |||||||||
| 35 | 35 | ▶ | while ($content) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 49 | my $space_index = index( $content, ' ' ); | |||||||||
| 37 | 49 | my $mode = substr( $content, 0, $space_index ); | |||||||||
| 38 | 49 | $content = substr( $content, $space_index + 1 ); | |||||||||
| 39 | 49 | my $null_index = index( $content, "\0" ); | |||||||||
| 40 | 49 | my $filename = substr( $content, 0, $null_index ); | |||||||||
| 41 | 49 | $content = substr( $content, $null_index + 1 ); | |||||||||
| 42 | 49 | my $sha1 = unpack( 'H*', substr( $content, 0, 20 ) ); | |||||||||
| 43 | 49 | $content = substr( $content, 20 ); | |||||||||
| 44 | 49 | ▶ | push @directory_entries, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | Cogit::DirectoryEntry->new( | ||||||||||
| 46 | mode => $mode, | ||||||||||
| 47 | filename => $filename, | ||||||||||
| 48 | sha1 => $sha1, | ||||||||||
| 49 | ( | ||||||||||
| 50 | $self->git | ||||||||||
| 51 | ? (git => $self->git) | ||||||||||
| 52 | : () | ||||||||||
| 53 | ), | ||||||||||
| 54 | ); | ||||||||||
| 55 | } | ||||||||||
| 56 | 35 | $self->directory_entries( \@directory_entries ); | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 4 | 1; | |||||||||
| 60 | |||||||||||
| 61 | __END__ | ||||||||||