├── README.md └── virtualenv.pl /README.md: -------------------------------------------------------------------------------- 1 | perl-virtualenv 2 | =============== 3 | 4 | Virtual Environment for Perl 5 | 6 | Usage 7 | ----- 8 | 9 | ### Activate & deactivate 10 | 11 | ```bash 12 | $ cd /path/to/project 13 | $ /path/to/perl/bin/virtualenv.pl venv 14 | $ source venv/bin/activate 15 | (venv) $ perl -v 16 | (venv) $ cpanm -v 17 | (venv) $ deactivate 18 | $ perl -v 19 | ``` 20 | 21 | ### Use it directly 22 | 23 | ```bash 24 | $ /path/to/project/venv/bin/perl -v 25 | ``` 26 | -------------------------------------------------------------------------------- /virtualenv.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Config; 7 | use File::Path qw(make_path); 8 | use File::Basename qw(dirname); 9 | use File::Spec::Functions qw(file_name_is_absolute); 10 | use Cwd qw(abs_path); 11 | 12 | my $perl = $Config{perlpath}; 13 | my $venv = shift || 'venv'; 14 | 15 | if (!file_name_is_absolute($venv)) { 16 | $venv = abs_path . "/$venv"; 17 | } 18 | 19 | if (! -d "$venv/bin") { 20 | make_path "$venv/bin" or die "Unable to create directory '$venv/bin'.\n" 21 | } 22 | 23 | print "perl: $perl\n"; 24 | print "venv: $venv\n"; 25 | 26 | sub spit { 27 | open my $fd, '>', shift; 28 | print $fd shift; 29 | close $fd; 30 | } 31 | 32 | spit "$venv/bin/perl", <