Apache-CVS

 view release on metacpan or  search on metacpan

CVS/File.pm  view on Meta::CPAN


sub rcs {
    my $self = shift;

    if (scalar @_) {
        $self->{rcs} = shift;
        $self->rcs_stale(0);
    }

    # in case the path of our File has changed
    if ((not $self->{rcs}) || $self->rcs_stale()) {
        $self->{rcs} = _setup_rcs($self->path(), $self->rcs_config());
        $self->rcs_stale(0);
    }

    return $self->{rcs};
}

=item $versioned_file->path([$new_path])

Get or set the path of this file.

=cut

sub path {
    my $self = shift;
    if ( scalar @_ ) {
        $self->{path} = shift;
        $self->{rcs_stale} = 1;
    }
    return $self->{path};
}

sub _find_adjacent_revision {
    my ($revision, $revisions, $increment) = @_;

    my $rev_num = $revision->number();
    my $index = 0;

    for ($index = 0; $revisions->[$index]; $index++) {
        last if ($revisions->[$index] eq $rev_num);
    }

    return $revisions->[--$index] if $increment;
    return $revisions->[++$index];
}

sub _revision_exists {
    my ($revisions, $revision) = @_;
    foreach my $current ( @{ $revisions } ) {
        if ( $current eq $revision ) {
            return 1;
        }
    }
    return 0;
}

sub _setup_rcs {
    my ($path, $config) = @_;
    my $rcs = Rcs->new($path);
    Rcs->bindir($config->binary());
    Rcs->arcext($config->extension());
    $rcs->workdir($config->working());
    return $rcs;
}

sub rcs_stale {
    my $self = shift;
    $self->{rcs_stale} = shift if scalar @_;
    return $self->{rcs_stale};
}

=item $versioned_file->revisions()

Returns a reference to a list of C<Apache::CVS::Revision> objects in no
particular order.

=cut

sub revisions {
    my $self = shift;

    my @revisions = map {
                        Apache::CVS::Revision->new($self->rcs(), $_)
                    } $self->rcs()->revisions;
    return \@revisions;
}

=item $versioned_file->revision($index)

Returns a C<Apache::CVS::Revision> object for the given index. The index
can be an absolute revision number (1.1, 1.2, 1.3.2.4) or one of the following:
first, next, prev, last. Using the 'next' index  on the first invocation of
this method result in the same thing as using 'first'. Similarly using 'prev'
on the first invocation is the same and using 'last'. If no revision can be
found, the method will return undef.

=cut

sub revision {
    my $self = shift;
    my $revision = shift;
    my $revision_number = undef;
    my @revisions;

    @revisions = $self->rcs()->revisions;
    $self->revision_count(scalar @revisions);

    if ( $revision eq 'first' ) {
        $revision_number = $revisions[-1];
    } elsif ( $revision eq 'next' ) {
        if ( $self->current_revision() ) {
            $revision_number =
                _find_adjacent_revision($self->current_revision(),
                                        \@revisions, 1);
        } else {
            # default to first if we do not already have a revision number
            $revision_number = $revisions[-1];
        }
    } elsif ( $revision eq 'prev' ) {
        if ($self->current_revision()) {



( run in 1.238 second using v1.01-cache-2.11-cpan-2398b32b56e )