File Coverage

File:lib/Parrot/Revision.pm
Coverage:73.9%

linestmtbrancondsubcode
1# Copyright (C) 2005-2011, Parrot Foundation.
2
3 - 27
=head1 NAME

Parrot::Revision - Revision number of Parrot

B<Note:> This package is largely obsolete, as the Git version control system
does not use a continually incrementing integer to designate a particular
revision, as our previous CVS and Subversion VCSes did.  We retain it for
backwards compatibility for certain high-level languages built on top of
Parrot.

=head1 SYNOPSIS

    use Parrot::Revision;

    print $Parrot::Revision::current;

=head1 DESCRIPTION

Get parrot's current and configure time revision.

We currently always return "1" to tell old HLL's that this version of Parrot is too new for them.
There is currently no way to say "we are too new for you", so we have to lie again and say we are
too old.

=cut
28
29package Parrot::Revision;
30
31
3
3
3
use strict;
32
3
3
3
use warnings;
33
3
3
3
use lib qw( lib );
34
3
3
3
use Parrot::Configure::Utils qw( :cache );
35
36our $cache = q{.parrot_current_rev};
37
38our $current = _get_revision();
39
40sub update {
41
1
    my $prev = _get_revision();
42
1
    my $revision = 1;
43
1
    $current = _handle_update( {
44        prev => $prev,
45        revision => $revision,
46        cache => $cache,
47        current => $current,
48    } );
49}
50
51sub _handle_update {
52
1
    my $args = shift;
53
1
    if (! defined $args->{revision}) {
54
0
        $args->{revision} = 'unknown';
55
0
        print_to_cache($args->{cache}, $args->{revision});
56
0
        return $args->{revision};
57    }
58    else {
59
1
        if (defined ($args->{prev}) && ($args->{revision} ne $args->{prev})) {
60
0
            print_to_cache($args->{cache}, $args->{revision});
61
0
            return $args->{revision};
62        }
63        else {
64
1
            return $args->{current};
65        }
66    }
67}
68
69sub _get_revision {
70
4
    my $revision;
71
4
    if (-f $cache) {
72
4
        $revision = read_from_cache($cache);
73    }
74    else {
75
0
        $revision = 1;
76
0
        print_to_cache($cache, $revision);
77    }
78
4
    return $revision;
79}
80
811;
82
83# Local Variables:
84# mode: cperl
85# cperl-indent-level: 4
86# fill-column: 100
87# End:
88# vim: expandtab shiftwidth=4: