| 1 | package Git::Gitalist::Object; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 2 | ▶ | use Moose; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | 2 | with 'Git::Gitalist::Serializable'; | |||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | 2 | ▶ | use Method::Signatures; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | 2 | ▶ | use MooseX::Types::Moose qw/Str Int Bool Maybe ArrayRef/; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | 2 | ▶ | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | 2 | ▶ | use Git::Gitalist::Types qw/SHA1/; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | 2 | ▶ | use overload '""' => '_to_string', fallback => 1; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | # repository and sha1 are required initargs | ||||||||||||||||||||||
| 17 | 2 | has repository => ( | |||||||||||||||||||||
| 18 | isa => 'Git::Gitalist::Repository', | ||||||||||||||||||||||
| 19 | required => 1, | ||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||
| 21 | weak_ref => 1, | ||||||||||||||||||||||
| 22 | handles => { | ||||||||||||||||||||||
| 23 | _run_cmd => 'run_cmd', | ||||||||||||||||||||||
| 24 | _run_cmd_fh => 'run_cmd_fh', | ||||||||||||||||||||||
| 25 | _run_cmd_list => 'run_cmd_list', | ||||||||||||||||||||||
| 26 | _get_gpp_object => 'get_gpp_object', | ||||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | 2 | has sha1 => ( | |||||||||||||||||||||
| 31 | isa => SHA1, | ||||||||||||||||||||||
| 32 | required => 1, | ||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||
| 35 | |||||||||||||||||||||||
| 36 | 2 | has type => ( | |||||||||||||||||||||
| 37 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||
| 39 | required => 1, | ||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | 2 | has modestr => ( | |||||||||||||||||||||
| 43 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||
| 44 | required => 1, | ||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||
| 46 | lazy_build => 1, | ||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | 2 | has size => ( | |||||||||||||||||||||
| 50 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||
| 51 | required => 1, | ||||||||||||||||||||||
| 52 | is => 'ro', | ||||||||||||||||||||||
| 53 | lazy_build => 1, | ||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||
| 55 | |||||||||||||||||||||||
| 56 | 2 | has _gpp_obj => ( | |||||||||||||||||||||
| 57 | isa => 'Git::PurePerl::Object', | ||||||||||||||||||||||
| 58 | required => 1, | ||||||||||||||||||||||
| 59 | is => 'ro', | ||||||||||||||||||||||
| 60 | lazy_build => 1, | ||||||||||||||||||||||
| 61 | handles => [ 'content' ], | ||||||||||||||||||||||
| 62 | traits => ['DoNotSerialize'], | ||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||
| 64 | |||||||||||||||||||||||
| 65 | # objects can't determine their mode or filename | ||||||||||||||||||||||
| 66 | 2 | has file => ( | |||||||||||||||||||||
| 67 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||
| 68 | required => 0, | ||||||||||||||||||||||
| 69 | is => 'ro', | ||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | 2 | has mode => ( | |||||||||||||||||||||
| 73 | isa => Int, | ||||||||||||||||||||||
| 74 | required => 1, | ||||||||||||||||||||||
| 75 | default => 0, | ||||||||||||||||||||||
| 76 | is => 'ro', | ||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||
| 78 | |||||||||||||||||||||||
| 79 | 2 | ▶ | method BUILD($args) { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BUILD: called CC=4 SCAR=14.1
Branch: 2 branches
| |||||||||||||||||||||||
| 80 | 4 | $self->$_() for qw/_gpp_obj size modestr/ | |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | ## Private methods | ||||||||||||||||||||||
| 84 | 0 | ▶ | method _to_string(...) { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
_to_string: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||
| 85 | 0 | return $self->sha1; | |||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | ## Builders | ||||||||||||||||||||||
| 89 | 2 | ▶ | method _build__gpp_obj { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
_build__gpp_obj: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||
| 90 | 4 | return $self->_get_gpp_object($self->sha1) | |||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||
| 92 | |||||||||||||||||||||||
| 93 | 2 | ▶ | method _build_size { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
_build_size: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||
| 94 | 4 | my $v = $self->_cat_file_with_flag('s'); | |||||||||||||||||||||
| 95 | 4 | chomp($v); | |||||||||||||||||||||
| 96 | 4 | return $v; | |||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||
| 98 | |||||||||||||||||||||||
| 99 | 2 | ▶ | method _cat_file_with_flag ($flag) { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
_cat_file_with_flag: called CC=3 SCAR=11.2
Branch: 2 branches
| |||||||||||||||||||||||
| 100 | $self->_run_cmd('cat-file', '-' . $flag, $self->{sha1}) | ||||||||||||||||||||||
| 101 | 4 | } | |||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | 2 | ▶ | method _build_modestr { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
_build_modestr: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||
| 104 | 4 | return mode_string($self->mode); | |||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||
| 106 | |||||||||||||||||||||||
| 107 | |||||||||||||||||||||||
| 108 | # via gitweb.pm circa line 1305 | ||||||||||||||||||||||
| 109 | 2 | ▶ | use Fcntl ':mode'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 110 | 2 | ▶ | use constant { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 111 | 2 | S_IFINVALID => 0030000, | |||||||||||||||||||||
| 112 | S_IFGITLINK => 0160000, | ||||||||||||||||||||||
| 113 | 2 | }; | |||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | # submodule/subrepository, a commit object reference | ||||||||||||||||||||||
| 116 | 4 | ▶ | sub S_ISGITLINK($) { | ||||||||||||||||||||
|
Subroutine
S_ISGITLINK: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 117 | 4 | return (($_[0] & S_IFMT) == S_IFGITLINK) | |||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||
| 119 | |||||||||||||||||||||||
| 120 | # convert file mode in octal to symbolic file mode string | ||||||||||||||||||||||
| 121 | 4 | ▶ | sub mode_string { | ||||||||||||||||||||
|
Subroutine
mode_string: called CC=7 SCAR=29.8
Pod
undocumented
| |||||||||||||||||||||||
| 122 | 4 | my $mode = shift; | |||||||||||||||||||||
| 123 | |||||||||||||||||||||||
| 124 | 4 | ▶ | if (S_ISGITLINK($mode)) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 125 | 0 | return 'm---------'; | |||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||
| 127 | elsif (S_ISDIR($mode & S_IFMT)) { | ||||||||||||||||||||||
| 128 | 0 | return 'drwxr-xr-x'; | |||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||
| 130 | ▶ | elsif ($^O ne 'MSWin32' and S_ISLNK($mode)) { # this is ENOLINKS country, we can't stop here! | |||||||||||||||||||||
|
Condition33%1/3
$^O ne "MSWin32" and S_ISLNK($mode)
MC/DC0%0/2
$^O ne "MSWin32" and S_ISLNK($mode)
$^O ne "MSWin32"
S_ISLNK($mode)
Truth table33%1/3
A and B
A= $^O ne "MSWin32"B= S_ISLNK($mode)
| |||||||||||||||||||||||
| 131 | 0 | return 'lrwxrwxrwx'; | |||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||
| 133 | elsif (S_ISREG($mode)) { | ||||||||||||||||||||||
| 134 | # git cares only about the executable bit | ||||||||||||||||||||||
| 135 | 0 | ▶ | if ($mode & S_IXUSR) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 136 | 0 | return '-rwxr-xr-x'; | |||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||
| 138 | else { | ||||||||||||||||||||||
| 139 | 0 | return '-rw-r--r--'; | |||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||
| 142 | else { | ||||||||||||||||||||||
| 143 | 4 | return '----------'; | |||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||
| 146 | |||||||||||||||||||||||
| 147 | 2 | 1; | |||||||||||||||||||||
| 148 | |||||||||||||||||||||||
| 149 | __END__ | ||||||||||||||||||||||