Permalink
Browse files

Ported the bashrc functionality into cshrc.

1. Added 3 new files to $PERLBREW_ROOT/etc on perlbrew init.
   a. csh_wrapper
   b. csh_reinit
   c. csh_set_path
2. Modified cshrc
   a. Now uses csh_set_path
   b. Defines an alias for perlbrew that references csh_wrapper
3. Updated tests
   a.  installation-perlbrew-t now checks for the 3 new files.
  • Loading branch information...
1 parent 97bdecd commit a1fa37e5d6937958878de86866f1614572ee36b9 @matzsoft matzsoft committed Apr 21, 2012
Showing with 120 additions and 9 deletions.
  1. +117 −9 lib/App/perlbrew.pm
  2. +3 −0 t/installation-perlbrew.t
View
@@ -166,6 +166,109 @@ complete -F _perlbrew_compgen perlbrew
COMPLETION
}
+sub CSH_WRAPPER_CONTENT {
+ return <<'WRAPPER';
+set perlbrew_exit_status=0
+
+if ( $1 =~ -* ) then
+ set perlbrew_short_option=$1
+ shift
+else
+ set perlbrew_short_option=""
+endif
+
+switch ( $1 )
+ case use:
+ if ( $%2 == 0 ) then
+ if ( $?PERLBREW_PERL == 0 ) then
+ echo "Currently using system perl"
+ else
+ if ( $%PERLBREW_PERL == 0 ) then
+ echo "Currently using system perl"
+ else
+ echo "Currently using $PERLBREW_PERL"
+ endif
+ endif
+ else
+ set perlbrew_line_count=0
+ foreach perlbrew_line ( "`\perlbrew env $2`" )
+ eval $perlbrew_line
+ @ perlbrew_line_count++
+ end
+ if ( $perlbrew_line_count == 0 ) then
+ set perlbrew_exit_status=1
+ else
+ source "$PERLBREW_ROOT/etc/csh_set_path"
+ endif
+ endif
+ breaksw
+
+ case switch:
+ if ( $%2 == 0 ) then
+ \perlbrew switch
+ else
+ perlbrew use $2 && source $PERLBREW_ROOT/etc/csh_reinit $2
+ endif
+ breaksw
+
+ case off:
+ unsetenv PERLBREW_PERL
+ foreach perlbrew_line ( "`\perlbrew env`" )
+ eval $perlbrew_line
+ end
+ source $PERLBREW_ROOT/etc/csh_set_path
+ echo "perlbrew is turned off."
+ breaksw
+
+ case switch-off:
+ unsetenv PERLBREW_PERL
+ source $PERLBREW_ROOT/etc/csh_reinit ''
+ echo "perlbrew is switched off."
+ breaksw
+
+ default:
+ \perlbrew $perlbrew_short_option $argv
+ set perlbrew_exit_status=$?
+ breaksw
+endsw
+rehash
+exit $perlbrew_exit_status
+WRAPPER
+}
+
+sub CSH_REINIT_CONTENT {
+ return <<'REINIT';
+if ( ! -d "$PERLBREW_HOME" ) then
+ mkdir -p "$PERLBREW_HOME"
+endif
+
+echo '# DO NOT EDIT THIS FILE' >! "$PERLBREW_HOME/init"
+\perlbrew env $1 >> "$PERLBREW_HOME/init"
+source "$PERLBREW_HOME/init"
+source "$PERLBREW_ROOT/etc/csh_set_path"
+REINIT
+}
+
+sub CSH_SET_PATH_CONTENT {
+ return <<'SETPATH';
+unalias perl
+
+if ( $?PERLBREW_PATH == 0 ) then
+ setenv PERLBREW_PATH "$PERLBREW_ROOT/bin"
+endif
+
+setenv PATH_WITHOUT_PERLBREW `perl -e 'print join ":", grep { index($_, $ENV{PERLBREW_ROOT}) } split/:/,$ENV{PATH};'`
+setenv PATH ${PERLBREW_PATH}:${PATH_WITHOUT_PERLBREW}
+
+setenv MANPATH_WITHOUT_PERLBREW `perl -e 'print join ":", grep { index($_, $ENV{PERLBREW_ROOT}) } split/:/,$ENV{MANPATH};'`
+if ( $?PERLBREW_MANPATH == 1 ) then
+ setenv MANPATH ${PERLBREW_MANPATH}:${MANPATH_WITHOUT_PERLBREW}
+else
+ setenv MANPATH ${MANPATH_WITHOUT_PERLBREW}
+endif
+SETPATH
+}
+
sub CSHRC_CONTENT {
return "setenv PERLBREW_CSHRC_VERSION $VERSION\n\n" . <<'CSHRC';
@@ -187,15 +290,8 @@ if ( $?PERLBREW_PATH == 0 ) then
setenv PERLBREW_PATH "$PERLBREW_ROOT/bin"
endif
-setenv PATH_WITHOUT_PERLBREW `perl -e 'print join ":", grep { index($_, $ENV{PERLBREW_ROOT}) } split/:/,$ENV{PATH};'`
-setenv PATH ${PERLBREW_PATH}:${PATH_WITHOUT_PERLBREW}
-
-setenv MANPATH_WITHOUT_PERLBREW `perl -e 'print join ":", grep { index($_, $ENV{PERLBREW_ROOT}) } split/:/,$ENV{MANPATH};'`
-if ( $?PERLBREW_MANPATH == 1 ) then
- setenv MANPATH ${PERLBREW_MANPATH}:${MANPATH_WITHOUT_PERLBREW}
-else
- setenv MANPATH ${MANPATH_WITHOUT_PERLBREW}
-endif
+source "$PERLBREW_ROOT/etc/csh_set_path"
+alias perlbrew 'source $PERLBREW_ROOT/etc/csh_wrapper'
CSHRC
}
@@ -655,6 +751,18 @@ sub run_command_init {
print BASH_COMPLETION BASH_COMPLETION_CONTENT;
close BASH_COMPLETION;
+ open CSH_WRAPPER, ">", catfile($self->root, "etc", "csh_wrapper");
+ print CSH_WRAPPER CSH_WRAPPER_CONTENT;
+ close CSH_WRAPPER;
+
+ open CSH_REINIT, ">", catfile($self->root, "etc", "csh_reinit");
+ print CSH_REINIT CSH_REINIT_CONTENT;
+ close CSH_REINIT;
+
+ open CSH_SET_PATH, ">", catfile($self->root, "etc", "csh_set_path");
+ print CSH_SET_PATH CSH_SET_PATH_CONTENT;
+ close CSH_SET_PATH;
+
open CSHRC, ">", catfile($self->root, "etc", "cshrc");
print CSHRC CSHRC_CONTENT;
close CSHRC;
@@ -25,6 +25,9 @@ subtest "`perlbrew self-install` initialize the required dir structure under PER
ok -f file($ENV{PERLBREW_ROOT}, "bin", "perlbrew");
ok -f file($ENV{PERLBREW_ROOT}, "etc", "bashrc");
ok -f file($ENV{PERLBREW_ROOT}, "etc", "cshrc");
+ ok -f file($ENV{PERLBREW_ROOT}, "etc", "csh_reinit");
+ ok -f file($ENV{PERLBREW_ROOT}, "etc", "csh_set_path");
+ ok -f file($ENV{PERLBREW_ROOT}, "etc", "csh_wrapper");
};
done_testing;

0 comments on commit a1fa37e

Please sign in to comment.