| 1 | package GitStore::Revision; | ||
| 2 | BEGIN { | ||
| 3 | 14 | ▶ | $GitStore::Revision::AUTHORITY = 'cpan:YANICK'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | } | ||
| 5 | #ABSTRACT: the state of a given path for a specific commit | ||
| 6 | 14 | $GitStore::Revision::VERSION = '0.16'; | |
| 7 | |||
| 8 | 14 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 14 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 14 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | 14 | ▶ | use GitStore; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 14 | ▶ | use DateTime; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 14 | ▶ | use List::Util qw/ first /; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | 14 | ▶ | use Path::Class; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | |||
| 18 | |||
| 19 | 14 | has sha1 => ( | |
| 20 | is => 'ro', | ||
| 21 | required => 1, | ||
| 22 | ); | ||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | has commit_object => ( | ||
| 28 | is => 'ro', | ||
| 29 | lazy => 1, | ||
| 30 | default => sub { | ||
| 31 | 6 | ▶ | my $self = shift; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 32 | |||
| 33 | 6 | return $self->git->get_object($self->sha1); | |
| 34 | }, | ||
| 35 | 14 | handles => { | |
| 36 | timestamp => 'authored_time', | ||
| 37 | message => 'comment', | ||
| 38 | }, | ||
| 39 | ); | ||
| 40 | |||
| 41 | |||
| 42 | 14 | has path => ( | |
| 43 | is => 'ro', | ||
| 44 | required => 1, | ||
| 45 | ); | ||
| 46 | |||
| 47 | 14 | has gitstore => ( | |
| 48 | is => 'ro', | ||
| 49 | isa => 'GitStore', | ||
| 50 | required => 1, | ||
| 51 | handles => { | ||
| 52 | git_repo => 'git_repo', | ||
| 53 | git => 'git', | ||
| 54 | }, | ||
| 55 | ); | ||
| 56 | |||
| 57 | has file_object => ( | ||
| 58 | is => 'ro', | ||
| 59 | lazy => 1, | ||
| 60 | default => sub { | ||
| 61 | 6 | ▶ | my $self = shift; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 62 | |||
| 63 | 6 | $self->gitstore->_find_file( | |
| 64 | $self->commit_object->tree, file($self->path) | ||
| 65 | ); | ||
| 66 | }, | ||
| 67 | 14 | ); | |
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | sub content { | ||
| 72 | 6 | ▶ | my $self = shift; |
|
Subroutine
content: called CC=1 SCAR=0.0
Pod
documented
| |||
| 73 | |||
| 74 | 6 | $self->gitstore->deserializer->($self->gitstore,$self->path,$self->file_object->object->content); | |
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | 14 | __PACKAGE__->meta->make_immutable; | |
| 79 | 14 | 1; | |
| 80 | |||
| 81 | __END__ | ||
| 82 | |||
| 83 | =pod | ||
| 84 | |||
| 85 | =encoding UTF-8 | ||
| 86 | |||
| 87 | =head1 NAME | ||
| 88 | |||
| 89 | GitStore::Revision - the state of a given path for a specific commit | ||
| 90 | |||
| 91 | =head1 VERSION | ||
| 92 | |||
| 93 | version 0.16 | ||
| 94 | |||
| 95 | =head1 SYNOPSIS | ||
| 96 | |||
| 97 | use GitStore; | ||
| 98 | |||
| 99 | my $gs = GitStore->new('/path/to/repo'); | ||
| 100 | |||
| 101 | my @history = $gs->history( 'path/to/object' ); | ||
| 102 | |||
| 103 | for my $rev ( @history ) { | ||
| 104 | say "modified at: ", $rev->timestamp; | ||
| 105 | say "commit message was: ", $rev->message; | ||
| 106 | say "===\n", $rev->content; | ||
| 107 | } | ||
| 108 | |||
| 109 | =head1 DESCRIPTION | ||
| 110 | |||
| 111 | Represents an object in a L<GitStore> at a specific commit. | ||
| 112 | |||
| 113 | =head1 METHODS | ||
| 114 | |||
| 115 | =head2 sha1 | ||
| 116 | |||
| 117 | Returns the SHA-1 of the commit. | ||
| 118 | |||
| 119 | =head2 commit_object | ||
| 120 | |||
| 121 | Returns the L<Git::PurePerl::Object::Commit> object containing the file revision. | ||
| 122 | |||
| 123 | =head2 timestamp | ||
| 124 | |||
| 125 | Returns the commit time of the revision as a L<DateTime> object. | ||
| 126 | |||
| 127 | =head2 message | ||
| 128 | |||
| 129 | Returns the commit message of the revision. Note that the message might have | ||
| 130 | additional trailing carriage returns. | ||
| 131 | |||
| 132 | =head2 path | ||
| 133 | |||
| 134 | Returns the path of the L<GitStore> object. | ||
| 135 | |||
| 136 | =head2 content | ||
| 137 | |||
| 138 | Returns the content of the object. If the object is a frozen ref, the | ||
| 139 | structure will be returned, like for `GitStore`'s `get()`. | ||
| 140 | |||
| 141 | =head1 AUTHORS | ||
| 142 | |||
| 143 | =over 4 | ||
| 144 | |||
| 145 | =item * | ||
| 146 | |||
| 147 | Fayland Lam <fayland@gmail.com> | ||
| 148 | |||
| 149 | =item * | ||
| 150 | |||
| 151 | Yanick Champoux <yanick@cpan.org> | ||
| 152 | |||
| 153 | =back | ||
| 154 | |||
| 155 | =head1 COPYRIGHT AND LICENSE | ||
| 156 | |||
| 157 | This software is copyright (c) 2015 by Fayland Lam <fayland@gmail.com>. | ||
| 158 | |||
| 159 | This is free software; you can redistribute it and/or modify it under | ||
| 160 | the same terms as the Perl 5 programming language system itself. | ||
| 161 | |||
| 162 | =cut | ||