Apache::CVS::Revision - class that implements a CVS revision


Apache-CVS documentation Contained in the Apache-CVS distribution.

Index


Code Index:

NAME

Top

Apache::CVS::Revision - class that implements a CVS revision

SYNOPSIS

Top

 use Rcs();
 use Apache::CVS::Revision();

 $revision = Apache::CVS::Revision->new($rcs, '1.2');

 $person_who_broke_build = $revision->author();
 $number =          $revision->number();
 $state =           $revision->state();
 $symbol =          $revision->symbol();
 $epoch =           $revision->date();
 $the_bright_idea = $revision->comment();
 %age =             %{ $revision->age() };
 $is_binary =       $revision->is_binary();
 $fh =              $revision->filehandle();
 $content =         $revision->content();
 $rcs =             $revision->rcs();

DESCRIPTION

Top

The Apache::CVS::Revision class implements a CVS revision.

Apache::CVS::Revision->new($rcs, $revision_number)

Construct a new Apache::CVS::Revision. The first argument is a instance of the Rcs class. The second is the revision number of this revision.

$revision->number()

Returns the number of the revision.

$revision->author()

Returns the author of the revision.

$revision->state()

Returns the state of the revision.

$revision->symbol()

Returns the symbol of the revision.

$revision->date()

Returns the date of the revision in Unix epoch time.

$revision->comment()

Returns the comments associated with this revision.

$revision->age()

Returns a hash that indicates the age of the revision. The keys of this hash are: days, hours, minutes, and seconds.

$revision->is_binary()

Returns true if the revision is binary and false otherwise.

$revision->filehandle()

Returns the filehandle of a checkout of this revision. The consumer is is responsible for closing this filehandle once they are done.

$revision->content()

Returns the content of this revision as a string.

$revision->rcs()

Returns the Rcs object of this revision.

SEE ALSO

Top

Apache::CVS, Rcs

AUTHOR

Top

John Barbee <barbee@veribox.net>

COPYRIGHT

Top


Apache-CVS documentation Contained in the Apache-CVS distribution.
# $Id: Revision.pm,v 1.5 2003/01/28 21:50:58 barbee Exp $

package Apache::CVS::Revision;

use strict;

$Apache::CVS::Revision::VERSION = $Apache::CVS::VERSION;

sub _new_rcs {
    my ($rcs, $revision) = @_;
    my $self = {};

    eval {
        $self->{rcs} = $rcs;
        $self->{number} = $revision;
        $self->{author} = $rcs->author($self->{number});
        $self->{state} = $rcs->state($self->{number});
        my @symbols = $rcs->symbol($self->{number});
        $self->{symbol} = \@symbols;
        $self->{date} = $rcs->revdate($self->{number});
        my %comments = $rcs->comments;
        $self->{comment} = $comments{$self->{number}};
    };
    if ( $@ ) {
        die "Apache::CVS::Revision : Received error from Rcs: $@\n";
    }
    return $self;
}

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self = undef;

    $self = _new_rcs(shift, shift);

    $self->{co_file} = undef;

    bless ($self, $class);
    return $self;
}

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

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

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

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

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

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

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

sub time_diff {

    my ($later, $earlier) = @_;
    my $seconds_in_minute = 60;
    my $seconds_in_hour = $seconds_in_minute * 60;
    my $seconds_in_day = $seconds_in_hour * 24;

    return undef unless $later >= $earlier;

    my %time;

    my $diff = $later - $earlier;

    my $remainder = $diff % $seconds_in_day;
    $time{days} = ($diff - $remainder) / $seconds_in_day;
    $diff = $remainder;

    $remainder = $diff % $seconds_in_hour;
    $time{hours} = ($diff - $remainder) / $seconds_in_hour;
    $diff = $remainder;

    $remainder = $diff % $seconds_in_minute;
    $time{minutes} = ($diff - $remainder) / $seconds_in_minute;
    $time{seconds} = $remainder;

    return \%time;
}

sub age {
    my $self = shift;
    return time_diff(time, $self->{date});
}

sub _checkout {
    my $self = shift;

    eval {
        $self->rcs()->co("-r" . $self->number());
        $self->co_file($self->rcs()->workdir . '/' . $self->rcs()->file);
    };

    if ($@) {
        die 'Apache::CVS::Revsion ' . $@;
    }
}

sub is_binary {
    my $self = shift;
    $self->_checkout() unless $self->co_file();
    return -B $self->co_file();
}

sub filehandle {
    my $self = shift;
    $self->_checkout() unless $self->co_file();
    open FILE, $self->co_file();
    return *FILE;
}

sub content {
    my $self = shift;
    $self->_checkout() unless $self->co_file();
    return undef if $self->is_binary();
    open FILE, $self->co_file();
    my $content = join '', <FILE>;
    close FILE;
    return $content;
}

sub rcs {
    my $self = shift;
    return $self->{rcs};
}

sub DESTROY {
    my $self = shift;
    unlink $self->co_file();
    $self->{number} = undef;
    $self->{author} = undef;
    $self->{state} = undef;
    $self->{symbol} = undef;
    $self->{date} = undef;
    $self->{comment} = undef;
    $self->{rcs} = undef;
    $self->{co_file} = undef;
}

1;