| 1 | package VCI::VCS::Svn::File; | ||
| 2 | use Moose; | ||
| 3 | |||
| 4 | with 'VCI::VCS::Svn::Committable'; | ||
| 5 | extends 'VCI::Abstract::File'; | ||
| 6 | |||
| 7 | use File::Temp; | ||
| 8 | |||
| 9 | # XXX Must implement this. | ||
| 10 | sub _build_is_executable { undef } | ||
| 11 | |||
| 12 | sub _build_content { | ||
| 13 | my $self = shift; | ||
| 14 | my $project = $self->project; | ||
| 15 | my $full_path = $project->repository->root . $project->name | ||
| 16 | . '/' . $self->path->stringify; | ||
| 17 | my $ctx = $project->vci->x_client; | ||
| 18 | my $temp = File::Temp->new; | ||
| 19 | $ctx->cat($temp, $full_path, $self->revision); | ||
| 20 | # For some reason, the actual file on disk contains data, but the | ||
| 21 | # filehandle does not. So we have to re-open the file. | ||
| 22 | close $temp; # Must close the file first or we can't read the whole thing. | ||
| 23 | open(my $temp_read, $temp->filename); | ||
| 24 | my $output; | ||
| 25 | { local $/ = undef; $output = <$temp_read>; } | ||
| 26 | close $temp_read; | ||
| 27 | return $output; | ||
| 28 | } | ||
| 29 | |||
| 30 | # We have to do this because ->isa File or Directory never | ||
| 31 | # returns true on a FileOrDirectory. | ||
| 32 | sub _me_from { | ||
| 33 | my $self = shift; | ||
| 34 | my $orig_class = blessed $self; | ||
| 35 | bless $self, 'VCI::VCS::Svn::FileOrDirectory'; | ||
| 36 | my $ret = $self->SUPER::_me_from(@_); | ||
| 37 | bless $self, $orig_class; | ||
| 38 | bless $ret, $orig_class; | ||
| 39 | return $ret; | ||
| 40 | }; | ||
| 41 | |||
| 42 | __PACKAGE__->meta->make_immutable; | ||
| 43 | |||
| 44 | 1; |