File Coverage

File:config/auto/stat.pm
Coverage:79.5%

linestmtbrancondsubcode
1# Copyright (C) 2010, Parrot Foundation.
2
3 - 11
=head1 NAME

config/auto/stat.pm - stat extension detection

=head1 DESCRIPTION

Determining if the system has BSD stat extensions.

=cut
12
13package auto::stat;
14
15
2
2
2
use strict;
16
2
2
2
use warnings;
17
18
2
2
2
use base qw(Parrot::Configure::Step);
19
20
2
2
2
use Parrot::Configure::Utils ':auto';
21
22sub _init {
23
2
    my $self = shift;
24
2
    my %data;
25
2
    $data{description} = q{Detect stat type};
26
2
    $data{result} = q{};
27
2
    return \%data;
28}
29
30sub runstep {
31
2
    my ( $self, $conf ) = @_;
32
33
2
    my $bsd_stat = 0;
34
35
2
    $conf->cc_gen('config/auto/stat/test_c.in');
36
2
2
    eval { $conf->cc_build(); };
37
2
    if (!$@) {
38
2
2
        my $output = eval { $conf->cc_run() };
39
2
        if (!$@ && $output =~ /OK/) {
40
2
            $bsd_stat = 1;
41        }
42    }
43
44
2
    $self->_handle_bsd_stat($conf, $bsd_stat);
45
2
    $conf->cc_clean();
46
47
2
    my $stat_atim = 0;
48
49
2
    $conf->cc_gen('config/auto/stat/test_atim_c.in');
50
2
2
    eval { $conf->cc_build(); };
51
2
    if (!$@) {
52
2
2
        my $output = eval { $conf->cc_run() };
53
2
        if (!$@ && $output =~ /OK/) {
54
2
            $stat_atim = 1;
55        }
56    }
57
2
    $conf->cc_clean();
58
59
2
    $conf->data->set( HAS_STAT_ATIM => $stat_atim );
60
61
2
    my $stat_atimespec = 0;
62
63
2
    $conf->cc_gen('config/auto/stat/test_atimespec_c.in');
64
2
2
    eval { $conf->cc_build(); };
65
2
    if (!$@) {
66
0
0
        my $output = eval { $conf->cc_run() };
67
0
        if (!$@ && $output =~ /OK/) {
68
0
            $stat_atimespec = 1;
69        }
70    }
71
2
    $conf->cc_clean();
72
73
2
    $conf->data->set( HAS_STAT_ATIMESPEC => $stat_atimespec );
74
75
2
    return 1;
76}
77
78sub _handle_bsd_stat {
79
4
    my ($self, $conf, $bsd_stat) = @_;
80
4
    if ($bsd_stat) {
81
3
        $conf->data->set( HAS_BSD_STAT_EXTN => 1 );
82
3
        $self->set_result('bsd');
83    }
84    else {
85
1
        $conf->data->set( HAS_BSD_STAT_EXTN => 0 );
86
1
        $self->set_result('posix');
87    }
88}
89
901;
91
92# Local Variables:
93# mode: cperl
94# cperl-indent-level: 4
95# fill-column: 100
96# End:
97# vim: expandtab shiftwidth=4:
98