File Coverage

File:config/auto/ctags.pm
Coverage:95.1%

linestmtbrancondsubcode
1# Copyright (C) 2005-2007, Parrot Foundation.
2# $Id: ctags.pm 47318 2010-06-03 01:36:45Z jkeenan $
3
4 - 16
=head1 NAME

config/auto/ctags - Check whether (exuberant) ctags works

=head1 DESCRIPTION

Determines whether exuberant ctags exists on the system. It is OK when it
doesn't exist.  This also checks if the ctags picked up is emacs ctags which
we B<don't> want to use.  On some systems exuberant ctags is called
C<ctags>, on some C<exuberant-ctags> and on others C<ctags-exuberant>.  This
test tries to work out which one we've got.

=cut
17
18package auto::ctags;
19
20
2
2
2
use strict;
21
2
2
2
use warnings;
22
23
2
2
2
use base qw(Parrot::Configure::Step);
24
25
2
2
2
use Parrot::Configure::Utils ':auto';
26
27sub _init {
28
5
    my $self = shift;
29
5
    my %data;
30
5
    $data{description} = q{Is (exuberant) ctags installed};
31
5
    $data{result} = q{};
32
5
    return \%data;
33}
34
35my @ctags_variations =
36    defined( $ENV{TEST_CTAGS} )
37    ? @{ $ENV{TEST_CTAGS} }
38    : qw( ctags exuberant-ctags ctags-exuberant exctags );
39
40sub runstep {
41
3
    my ( $self, $conf ) = @_;
42
43
3
    $conf->debug("\n");
44
45
3
    my ($ctags, $has_ctags) =
46        _probe_for_ctags($conf, [ @ctags_variations ]);
47
3
    $self->_evaluate_ctags($conf, $ctags, $has_ctags);
48
3
    return 1;
49}
50
51sub _probe_for_ctags {
52
3
    my $conf = shift;
53
3
    my $variations_ref = shift;
54
3
    my ($ctags, $has_ctags);
55
3
    while (defined (my $t = shift(@$variations_ref))) {
56
3
        my $output = capture_output( $t, '--version' ) || '';
57
3
        $conf->debug("$output\n");
58
3
        $has_ctags = _probe_for_ctags_output($conf, $output);
59
3
        $ctags = $t if $has_ctags;
60
3
        last if $has_ctags;
61    }
62
3
    return ($ctags, $has_ctags);
63}
64
65sub _probe_for_ctags_output {
66
7
    my ($conf, $output) = @_;
67
7
    my $has_ctags = ( $output =~ m/Exuberant Ctags/ ) ? 1 : 0;
68
7
    $conf->debug("$has_ctags\n");
69
7
    return $has_ctags;
70}
71
72sub _evaluate_ctags {
73
5
    my ($self, $conf, $ctags, $has_ctags) = @_;
74
5
    if ($has_ctags) {
75
4
        $conf->data->set( ctags => $ctags );
76
4
        $self->set_result( 'yes' );
77    }
78    else {
79
1
        $conf->data->set( ctags => 'ctags' );
80
1
        $self->set_result( 'no' );
81    }
82}
83
841;
85
86 - 90
=head1 AUTHOR

Paul Cochrane <paultcochrane at gmail dot com>

=cut
91
92# Local Variables:
93# mode: cperl
94# cperl-indent-level: 4
95# fill-column: 100
96# End:
97# vim: expandtab shiftwidth=4: