File Coverage

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

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

Paul Cochrane <paultcochrane at gmail dot com>

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