| File: | config/init/hints.pm |
| Coverage: | 89.2% |
| line | stmt | bran | cond | sub | code |
|---|---|---|---|---|---|
| 1 | # Copyright (C) 2001-2010, Parrot Foundation. | ||||
| 2 | |||||
| 3 - 12 | =head1 NAME config/init/hints.pm - Platform Hints =head1 DESCRIPTION Loads the platform and local hints files, modifying the defaults set up in F<config/init/default.pm>. =cut | ||||
| 13 | |||||
| 14 | package init::hints; | ||||
| 15 | |||||
| 16 | 3 3 3 | use strict; | |||
| 17 | 3 3 3 | use warnings; | |||
| 18 | |||||
| 19 | 3 3 3 | use File::Spec::Functions qw/catfile/; | |||
| 20 | 3 3 3 | use base qw(Parrot::Configure::Step); | |||
| 21 | |||||
| 22 | sub _init { | ||||
| 23 | 5 | my $self = shift; | |||
| 24 | 5 | my %data; | |||
| 25 | 5 | $data{description} = q{Load platform and local hints files}; | |||
| 26 | 5 | $data{result} = q{}; | |||
| 27 | 5 | return \%data; | |||
| 28 | } | ||||
| 29 | |||||
| 30 | sub runstep { | ||||
| 31 | 5 | my ( $self, $conf ) = @_; | |||
| 32 | |||||
| 33 | 5 | $conf->debug("\n[ "); | |||
| 34 | |||||
| 35 | 5 | my $hints_used = 0; | |||
| 36 | 5 | my $hints_file; | |||
| 37 | |||||
| 38 | 5 | my $osname = lc( $conf->data->get('OSNAME_provisional') ); | |||
| 39 | 5 | $osname = 'linux' if ($osname eq 'gnukfreebsd'); | |||
| 40 | |||||
| 41 | 5 | my $hints_file_name = $conf->options->get('hintsfile') || $osname ; | |||
| 42 | 5 | $hints_file = catfile('config', 'init', 'hints', "$hints_file_name.pm"); | |||
| 43 | |||||
| 44 | 5 | if ( -f $hints_file ) { | |||
| 45 | 4 | my $hints_pkg = "init::hints::" . $hints_file_name; | |||
| 46 | |||||
| 47 | 4 | $conf->debug("$hints_pkg "); | |||
| 48 | |||||
| 49 | 2 2 2 1 1 1 1 1 1 4 | eval "use $hints_pkg"; | |||
| 50 | 4 | die $@ if $@; | |||
| 51 | |||||
| 52 | # Call the runstep method if it exists. | ||||
| 53 | # Otherwise the step must have done its work when it was loaded. | ||||
| 54 | 4 | $hints_pkg->runstep( $conf, @_ ) if $hints_pkg->can('runstep'); | |||
| 55 | 4 | $hints_used++; | |||
| 56 | |||||
| 57 | 4 | $hints_pkg = "init::hints::local"; | |||
| 58 | 4 | $conf->debug("$hints_pkg "); | |||
| 59 | 2 0 0 1 1 1 1 1 1 4 | eval "use $hints_pkg"; | |||
| 60 | |||||
| 61 | 4 | unless ($@) { | |||
| 62 | 2 | $hints_pkg->runstep( $conf, @_ ) if $hints_pkg->can('runstep'); | |||
| 63 | 2 | $hints_used++; | |||
| 64 | } | ||||
| 65 | } | ||||
| 66 | elsif ( $conf->options->get('hintsfile') ) { | ||||
| 67 | 0 | die "No $hints_file found"; | |||
| 68 | } | ||||
| 69 | else { | ||||
| 70 | 1 | $conf->debug("No $hints_file found. "); | |||
| 71 | } | ||||
| 72 | |||||
| 73 | 5 | if ( $hints_used == 0 ) { | |||
| 74 | 1 | $conf->debug("(no hints) "); | |||
| 75 | } | ||||
| 76 | |||||
| 77 | 5 | $conf->debug("]"); | |||
| 78 | |||||
| 79 | 5 | return 1; | |||
| 80 | } | ||||
| 81 | |||||
| 82 | 1; | ||||
| 83 | |||||
| 84 | # Local Variables: | ||||
| 85 | # mode: cperl | ||||
| 86 | # cperl-indent-level: 4 | ||||
| 87 | # fill-column: 100 | ||||
| 88 | # End: | ||||
| 89 | # vim: expandtab shiftwidth=4: | ||||