Test-Smoke

 view release on metacpan or  search on metacpan

lib/Test/Smoke/BuildCFG.pm  view on Meta::CPAN

        $self->{_buildcfg} = join "", @$nameorref;
        $vmsg = "internal content";
    } elsif ( ref $nameorref eq 'HASH' ) {
        $self->{_buildcfg} = undef;
        $self->{_list} = $nameorref->{_list};
        $vmsg = "continuing smoke";
    } elsif ( ref $nameorref eq 'GLOB' ) {
        *BUILDCFG = *$nameorref;
        $self->{_buildcfg} = do { local $/; <BUILDCFG> };
        $vmsg = "anonymous filehandle";
    } else {
        if ( $nameorref ) {
            if ( open BUILDCFG, "< $nameorref" ) {
                $self->{_buildcfg} = do { local $/; <BUILDCFG> };
                close BUILDCFG;
                $vmsg = $nameorref;
            } else {
                require Carp;
                Carp::carp("Cannot read buildconfigurations ($nameorref): $!");
                $self->{_buildcfg} = $self->default_buildcfg();
                $vmsg = "internal content";
            }
        } else { # Allow intentional default_buildcfg()
            $self->{_buildcfg} = $self->default_buildcfg();
            $vmsg = "internal content";
        }
    }
    $vmsg .= "[continue]" if $self->{_continue};
    $self->log_info("Reading build configurations from %s", $vmsg);
}

=head2 $self->_parse( )

C<_parse()> will split the build configurations file in sections.
Sections are ended with a line that begins with an equals-sign ('=').

There are two types of section

=over

=item B<buildopt-section>

=item B<policy-section>

A B<policy-section> contains a "target-option". This is a build option
that should be in the ccflags variable in the F<Policy.sh> file
(see also L<Test::Smoke::Policy>) and starts with a (forward) slash ('/').

A B<policy-section> can have only one (1) target-option.

=back

=cut

sub _parse {
    my $self = shift;

    return unless defined $self->{_buildcfg}; # || $self->{_list};

    $self->{_sections} = [ ];
    my @sections = split m/^=.*\n/m, $self->{_buildcfg};
    $self->log_debug("Found %d raw-sections", scalar @sections);

    foreach my $section ( @sections ) {
        chomp $section;
        my $index = 0;
        my %opts = map { s/^\s+$//; $_ => $index++ }
            grep !/^#/ => split /\n/, $section, -1;
        # Skip empty sections
        next if (keys %opts == 0) or (exists $opts{ "" } and keys %opts == 1);

        if (  grep m|^/.+/?$| => keys %opts ) { # Policy section
            my @targets;
            my @lines = keys %opts;
            foreach my $line ( @lines ) {
                next unless $line =~ m|^/(.+?)/?$|;

                push @targets, $1;
                delete $opts{ $line };
            }
            if ( @targets > 1 ) {
                require Carp;
                Carp::carp( "Multiple policy lines in one section:\n\t",
                            join( "\n\t", @targets ),
                            "\nWill use /$targets[0]/\n" );
            }
            push @{ $self->{_sections} },
                 { policy_target => $targets[0],
                   args => [ sort {$opts{ $a } <=> $opts{ $b }} keys %opts ] };

        } else { # Buildopt section
            push @{ $self->{_sections} },
                 [ sort {$opts{ $a } <=> $opts{ $b }} keys %opts ];
        }
    }
    # Make sure we have at least *one* section
    push @{ $self->{_sections} }, [ "" ] unless @{ $self->{_sections} };

    $self->log_debug("Left with %d parsed sections", scalar @{$self->{_sections}});
    $self->_serialize;
    $self->log_debug("Found %d (unfiltered) configurations", scalar @{$self->{_list}});
}

=head2 $self->_serialize( )

C<_serialize()> creates a list of B<Test::Smoke::BuildCFG::Config>
objects from the parsed sections.

=cut

sub _serialize {
    my $self = shift;

    my $list = [ ];
    __build_list( $list, $self->{dfopts}, [ ], @{ $self->{_sections} } );

    $self->{_list} = $list;
}

=head2 __build_list( $list, $previous_args, $policy_subst, $this_cfg, @cfgs )



( run in 1.594 second using v1.01-cache-2.11-cpan-71847e10f99 )