package inc::Installer::ConfigFileWriter; use strict; use Config (); use inc::Installer::OutPaths; use inc::Config; use base qw( inc::Installer inc::Installer::Logger inc::Installer::OptionsProviderI inc::Installer::EUMMArgProviderI ); { my $SINGLETON; sub new { my $class = shift; if ( not $SINGLETON ) { my %files = @_; bless \%files, $class; $SINGLETON = \%files; } return $SINGLETON; } } sub _write_file { my ( $self, $filename, $content ) = @_; open my $fh, '>', $filename or die "Can't open '$filename': $!"; print $fh $content; close $fh; } sub WriteBashrc { my $self = shift; $self->debug("Writing .bashrc"); my $outPaths = inc::Installer::OutPaths->new; my $sep = $Config::Config{'path_sep'}; my $binpath = $outPaths->Installsitebin; my $perl5lib = $outPaths->MakePERL5LIB; my $bashrc = <<"!GROK!THIS!"; # bourne compatible environment variables PATH=$binpath$sep\$PATH; export PATH PERL5LIB=$perl5lib$sep\$PERL5LIB; export PERL5LIB PERL5OPT=-MCipres::Config\\ \$PERL5OPT; export PERL5OPT !GROK!THIS! $self->debug( $bashrc ); $self->_write_file( $outPaths->Configdir . '/' . $self->{'bashrc'}, $bashrc ); } sub WriteBat { my $self = shift; $self->debug("Writing .bat"); my $outPaths = inc::Installer::OutPaths->new; my $sep = $Config::Config{'path_sep'}; my $binpath = $outPaths->Installsitebin; my $perl5lib = $outPaths->MakePERL5LIB; my $configdir = $outPaths->Configdir; my $winbat = <<"!GROK!THIS!"; :: windows cmd compatible environment variables set PATH=$binpath$sep\%PATH% set PERL5LIB=$perl5lib$sep\%PERL5LIB% set PERL5OPT=-MCipres::Config \%PERL5OPT% #set PATHEXT=%PATHEXT%;.PL !GROK!THIS! $self->debug( $winbat ); $self->_write_file( $outPaths->Configdir . '/' . $self->{'winbat'}, $winbat ); } sub WriteProperties { my $self = shift; $self->debug("Writing .properties"); my $outPaths = inc::Installer::OutPaths->new; my $perl5lib = $outPaths->MakePERL5LIB; my $prefix = $outPaths->Prefix; $perl5lib =~ s/\Q$prefix\E/\@prefix\@\/lib\/perl/g; my $jprops = <<"!GROK!THIS!"; # Make configure's prefix arg accessible to ant: cipres.prefix=\@prefix\@ # path to perl to use when building framework/perl cipres.perl.exe=$Config::Config{perlpath} # Where we put the perl modules cipres.perl.lib.dir=\@prefix\@/lib/perl # The PERL5LIB we need to import our own perl modules (after "make install" is run) cipres.perl.PERL5LIB=$perl5lib # The PERL5OPT switch is used to modify perl's runtime behaviour cipres.perl.PERL5OPT=-MCipres::Config # More PERL5LIB entries so that we pick up prereq. This is just the PERL5LIB # at configure time. If we have the correct PERL5LIB for passing configure's tests # we should be able to run with that PERL5LIB plus the entries in cipres.perl.PERL5LIB) cipres.third.party.PERL5LIB=$ENV{PERL5LIB} !GROK!THIS! $self->debug( $jprops ); $self->_write_file( $outPaths->Configdir . '/' . $self->{'jprops'}, $jprops ); } sub WriteConfigPM { my $self = shift; $self->debug("Writing Config.pm"); my $outPaths = inc::Installer::OutPaths->new; $outPaths->ToGlobalConfig; my %Config = inc::Config::diff; my $configpm = <<'!NO!SUBS!'; package Cipres::Config; use Config (); my $MyConfig = tied %Config::Config; !NO!SUBS! for my $key ( sort { $a cmp $b } keys %Config ) { $configpm .= "\$MyConfig->{'$key'} = '$Config{$key}';\n"; } $configpm .= "\n1;\n"; $self->debug( $configpm ); $self->_write_file( $outPaths->Configdir . '/' . $self->{'confpm'}, $configpm ); } sub WriteCPANConfigPM { my $self = shift; } sub WriteRequestedFiles { my $self = shift; $self->debug("Writing requested files."); for my $file ( keys %$self ) { if ( $file eq 'bashrc' ) { $self->WriteBashrc( $self->{$file} ); } elsif ( $file eq 'winbat' ) { $self->WriteBat( $self->{$file} ); } elsif ( $file eq 'jprops' ) { $self->WriteProperties( $self->{$file} ); } elsif ( $file eq 'confpm' ) { $self->WriteConfigPM( $self->{$file} ); } else { $self->warning("Don't know how to write '$file'"); } } } sub Options { my $self = shift; my %options; for my $file ( qw(bashrc winbat jprops confpm) ) { $options{"write-$file=s"} = \$self->{$file}; } return %options; } sub OptionsHelp { my $self = shift; my $help = " Configuration output files:\n"; for my $file ( qw(bashrc winbat jprops confpm) ) { $help .= sprintf(" --write-$file=[PATH]\n Current setting: %s\n\n", $self->{$file} ); } return $help; } sub GetEUMMArgs { } 1;