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