~ubuntu-branches/ubuntu/quantal/libyaml-libyaml-perl/quantal-security

« back to all changes in this revision

Viewing changes to inc/Module/Install/VersionCheck.pm

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Krzyżaniak (eloy)
  • Date: 2010-09-24 17:35:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100924173542-7ajsmy5mmt6swpgh
Tags: 0.34-1
* New upstream release
* Update Standards-Version to 3.9.1 (no changes)
* Added me to Uploaders (debian/control) and debian/copyright file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#line 1
 
2
package Module::Install::VersionCheck;
 
3
use strict;
 
4
use warnings;
 
5
use 5.008003;
 
6
 
 
7
use Module::Install::Base;
 
8
 
 
9
my $DEFAULT = '0.00';
 
10
 
 
11
use vars qw($VERSION @ISA);
 
12
BEGIN {
 
13
    $VERSION = '0.10';
 
14
    @ISA     = 'Module::Install::Base';
 
15
}
 
16
 
 
17
sub version_check {
 
18
    my $self = shift;
 
19
    return unless $self->is_admin;
 
20
 
 
21
    my $module_version = $self->_get_module_version();
 
22
    my $changes_version = $self->_get_changes_version();
 
23
    my $git_tag_version = $self->_get_git_tag_version();
 
24
 
 
25
    $self->_report(
 
26
        $module_version,
 
27
        $changes_version,
 
28
        $git_tag_version,
 
29
    );
 
30
}
 
31
 
 
32
sub _get_module_version {
 
33
    my $self = shift;
 
34
    return $DEFAULT unless $self->admin->{extensions};
 
35
    my ($metadata) = grep {
 
36
        ref($_) eq 'Module::Install::Metadata';
 
37
    } @{$self->admin->{extensions}};
 
38
    return $DEFAULT unless $metadata;
 
39
    return $metadata->{values}{version} || $DEFAULT;
 
40
}
 
41
 
 
42
sub _get_changes_version {
 
43
    my $self = shift;
 
44
    return $DEFAULT unless -e 'Changes';
 
45
    open IN, 'Changes' or die "Can't open 'Changes' for input: $!";
 
46
    my $text = do {local $/; <IN>};
 
47
    $text =~ /\b(\d\.\d\d)\b/ or return $DEFAULT;
 
48
    return $1;
 
49
}
 
50
 
 
51
sub _get_git_tag_version {
 
52
    my $self = shift;
 
53
    return $DEFAULT unless -e '.git';
 
54
    require Capture::Tiny;
 
55
    my $text = Capture::Tiny::capture_merged(sub { system('git tag') });
 
56
    my $version = $DEFAULT;
 
57
    for (split "\n", $text) {
 
58
        if (/\b(\d\.\d\d)\b/ and $1 > $version) {
 
59
            $version = $1;
 
60
        }
 
61
    }
 
62
    return $version;
 
63
}
 
64
 
 
65
sub _report {
 
66
    my $self = shift;
 
67
    print "version_check found: @_\n";
 
68
}
 
69
 
 
70
1;
 
71
 
 
72
=encoding utf8
 
73
 
 
74
#line 107