| 1 | package Git::Database::Object::Tag; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 20 | $Git::Database::Object::Tag::VERSION = '0.012'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use Git::Database::Actor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 20 | ▶ | use Encode qw( decode ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 20 | with 'Git::Database::Role::Object'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 208 | ▶ | sub kind {'tag'} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kind: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 20 | has tag_info => ( | |||||||||||||||||||||||||||||||||||||||||
| 15 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||
| 16 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | builder => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 119 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 119 | ▶ | die "One of 'digest' or 'content' or 'tag_info' is required" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->has_digest || $self->has_content || $self->has_tag_info
$self->has_digest or $self->has_content
MC/DC100%3/3
$self->has_digest || $self->has_content || $self->has_tag_info
$self->has_digest
$self->has_content
$self->has_tag_info
Truth table100%4/4
A or B || C
A= $self->has_digestB= $self->has_contentC= $self->has_tag_info
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | if !$self->has_digest && !$self->has_content && !$self->has_tag_info; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 20 | for my $attr ( | |||||||||||||||||||||||||||||||||||||||||
| 29 | qw( | ||||||||||||||||||||||||||||||||||||||||||
| 30 | object | ||||||||||||||||||||||||||||||||||||||||||
| 31 | type | ||||||||||||||||||||||||||||||||||||||||||
| 32 | tag | ||||||||||||||||||||||||||||||||||||||||||
| 33 | tagger | ||||||||||||||||||||||||||||||||||||||||||
| 34 | tagger_date | ||||||||||||||||||||||||||||||||||||||||||
| 35 | comment | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 20 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 112 | ▶ | *$attr = sub { $_[0]->tag_info->{$attr} }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | sub _build_tag_info { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 59 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_tag_info: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 59 | ▶ | if ( !$self->has_content ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 14 | my $attr = $self->_get_object_attributes(); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 7 | ▶ | return $attr->{tag_info} if exists $attr->{tag_info}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 7 | ▶ | if ( exists $attr->{content} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 7 | $self->_set_content( $attr->{content} ); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | die "Can't build content from these attributes: " | |||||||||||||||||||||||||||||||||||||||||
| 55 | . join( ', ', sort keys %$attr ); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 52 | my $tag_info = {}; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 52 | my @lines = split "\n", $self->content; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 52 | ▶ | while ( my $line = shift @lines ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 208 | my ( $key, $value ) = split ' ', $line, 2; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 208 | ▶ | if ( $key eq 'tagger' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 52 | my @data = split ' ', $value; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 52 | my ( $email, $epoch, $tz ) = splice( @data, -3 ); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 52 | $tag_info->{tagger} = Git::Database::Actor->new( | |||||||||||||||||||||||||||||||||||||||||
| 68 | name => join( ' ', @data ), | ||||||||||||||||||||||||||||||||||||||||||
| 69 | email => substr( $email, 1, -1 ) | ||||||||||||||||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 52 | $tag_info->{tagger_date} = DateTime->from_epoch( | |||||||||||||||||||||||||||||||||||||||||
| 72 | epoch => $epoch, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | time_zone => $tz | ||||||||||||||||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 156 | $tag_info->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 52 | $tag_info->{comment} = join "\n", @lines; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 52 | return $tag_info; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | sub _build_content { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 51 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_content: called CC=5 SCAR=17.2
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 51 | ▶ | if ( ! $self->has_tag_info ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 35 | my $attr = $self->_get_object_attributes(); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 21 | ▶ | return $attr->{content} if exists $attr->{content}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ( exists $attr->{tag_info} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $self->_set_tag_info( $attr->{tag_info} ); | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | die "Can't build content from these attributes: " | |||||||||||||||||||||||||||||||||||||||||
| 96 | . join( ', ', sort keys %$attr ); | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 16 | my $content; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 16 | $content .= "$_ " . $self->$_ . "\n" for qw( object type tag ); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 16 | $content .= join( | |||||||||||||||||||||||||||||||||||||||||
| 103 | ' ', | ||||||||||||||||||||||||||||||||||||||||||
| 104 | tagger => $self->tagger->ident, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | $self->tagger_date->epoch, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | DateTime::TimeZone->offset_as_string( $self->tagger_date->offset ) | ||||||||||||||||||||||||||||||||||||||||||
| 107 | ) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 16 | $content .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 16 | my $comment = $self->comment; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 16 | chomp $comment; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 16 | $content .= "$comment\n"; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 16 | return $content; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =for Pod::Coverage | ||||||||||||||||||||||||||||||||||||||||||
| 123 | BUILD | ||||||||||||||||||||||||||||||||||||||||||
| 124 | has_tag_info | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | Git::Database::Object::Tag - A tag object in the Git database | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | version 0.012 | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | my $r = Git::Database->new(); # current Git repository | ||||||||||||||||||||||||||||||||||||||||||
| 137 | my $tag = $r->get_object('f5c10c'); # abbreviated digest | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | # attributes | ||||||||||||||||||||||||||||||||||||||||||
| 140 | $tag->kind; # tag | ||||||||||||||||||||||||||||||||||||||||||
| 141 | $tag->digest; # f5c10c1a841419d3b1db0c3e0c42b554f9e1eeb2 | ||||||||||||||||||||||||||||||||||||||||||
| 142 | $tag->object; # ef25e81ba86b7df16956c974c8a9c1ff2eca1326 | ||||||||||||||||||||||||||||||||||||||||||
| 143 | $tag->type; # commit | ||||||||||||||||||||||||||||||||||||||||||
| 144 | ...; # etc., see below | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | Git::Database::Object::Tag represents a C<tag> object | ||||||||||||||||||||||||||||||||||||||||||
| 149 | obtained via L<Git::Database> from a Git object database. | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | All major attributes (L</digest>, L</content>, L</size>, L</tag_info>) | ||||||||||||||||||||||||||||||||||||||||||
| 154 | have a predicate method. | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | =head2 kind | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | The object kind: C<tag> | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | =head2 digest | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | The SHA-1 digest of the digest object. | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | =head2 content | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | The object's actual content. | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | =head2 size | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | The size (in bytes) of the object content. | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | =head2 tag_info | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | A hash reference containing the all the attributes listed below, as | ||||||||||||||||||||||||||||||||||||||||||
| 175 | values for the keys with the same names. | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | =head2 object | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | The SHA-1 digest of the tagged object. | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | =head2 type | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | The type of the tagged object. | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | =head2 tag | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | The tag name. | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | =head2 tagger | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | A L<Git::Database::Actor> object representing the author of | ||||||||||||||||||||||||||||||||||||||||||
| 192 | the tag. | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | =head2 tagger_date | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | A L<DateTime> object representing the date at which the author | ||||||||||||||||||||||||||||||||||||||||||
| 197 | created the tag. | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | =head2 comment | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | The text of the tag. | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | =head2 new() | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | Create a new Git::Object::Database::Tag object. | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | One (and only one) of the C<content> or C<tag> arguments is | ||||||||||||||||||||||||||||||||||||||||||
| 210 | required. | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | C<tag_info> is a reference to a hash containing the keys listed | ||||||||||||||||||||||||||||||||||||||||||
| 213 | above, i.e. C<object>, C<type>, C<tag>, C<tagger>, C<tagger_time>, | ||||||||||||||||||||||||||||||||||||||||||
| 214 | and C<comment>. | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | L<Git::Database>, | ||||||||||||||||||||||||||||||||||||||||||
| 219 | L<Git::Database::Role::Object>. | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | Philippe Bruhat (BooK) <book@cpan.org>. | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | Copyright 2013-2016 Philippe Bruhat (BooK), all rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||
| 232 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | =cut | ||||||||||||||||||||||||||||||||||||||||||