v0.1.0.perl-dotenv/000755 000765 000000 00000000000 13123016136 014066 5ustar00ronwheel000000 000000 v0.1.0.perl-dotenv/._v0.1.0.DotenvSimple.pm000644 000765 000024 00000000322 13123007603 020074 0ustar00ronstaff000000 000000 Mac OS X  2 ÒATTRÒ¨*¨*$com.apple.metadata:_kMDItemUserTagsbplist00  v0.1.0.perl-dotenv/v0.1.0.DotenvSimple.pm000644 000765 000000 00000004207 13123007603 017660 0ustar00ronwheel000000 000000 # == Summery: == # Load dotenv from # 1. parameter passed # 2. predifined shell or HTTPD `DOTENV_FILE=./_path_to_dotenv` enviroment varaible # 3. `.env` in you HTTPD document DOCUMENT_ROOT. Check in your HTTPD document root for `.env` # # assign to global $ENV{} hash # # == Usage: == # Ensure this module is in a search path and... # # use DotenvSimple; # DotenvSimple::source_dotenv(); # # DotenvSimple::list_env(); package DotenvSimple; use strict; use base qw(Exporter); use Carp (); @DotenvSimple::EXPORT = qw(source_dotenv list_env); BEGIN { $DotenvSimple::VERSION = '0.1.0'; # $DotenvSimple::DEBUG = 0 unless (defined $DotenvSimple::DEBUG); $DotenvSimple::DEBUG = $ENV{ PERL_DOTENV_DEBUG } if exists $ENV{ PERL_DOTENV_DEBUG }; } ################### # load shell style enviroment vaiable, expect full file path as # sub source_dotenv { my ($my_dotenv_file) = @_; my $DOTENV_FILE; if ( -e $my_dotenv_file ) { #defined as an apache var $DOTENV_FILE = "$my_dotenv_file"; } elsif ( -e $ENV{DOTENV_FILE} ) { #defined as an apache var $DOTENV_FILE = "$ENV{DOTENV_FILE}"; } elsif ( -e $ENV{DOCUMENT_ROOT} ) { $DOTENV_FILE = "$ENV{DOCUMENT_ROOT}/.env"; } else { die "ERROR: Could not deterine dotenv location, please pass location as a parameter!"; } $DEBUG::DEBUG and Carp::carp("In DotenvSimple::source_dotenv processing $DOTENV_FILE"); open my $fh, "<", $DOTENV_FILE or die "could not open $DOTENV_FILE: $!"; FORA: while (<$fh>) { chomp; my ( $k, $v ) = split /=/, $_, 2; $k =~ s/^\s+|\s+$//g; $k =~ s/^export[\s\t]+//g; $v =~ s/^\s+|\s+$//g; $v =~ s/^(['"])(.*)\1/$2/; #' fix highlighter $v =~ s/\$([a-zA-Z]\w*)/$ENV{$1}/g; $v =~ s/`(.*?)`/`$1`/ge; #dangerous $v =~ s/[\;\,]$//; next FORA if ( $k =~ m/^$/ || $k =~ m/^\#.*/ ); $ENV{$k} = $v; $DEBUG::DEBUG and Carp::carp("ENV: $k => $v"); } } sub list_env { print "Content-type:text/html\n\n"; foreach ( sort keys %ENV ) { print "$_ = $ENV{$_}
\n"; } exit; } v0.1.0.perl-dotenv/v0.1.0.README.md000644 000765 000000 00000002633 13123014527 016174 0ustar00ronwheel000000 000000 # Perl Simple DotEnv load enviroment vaiabled with Perl from a file in `.env` (dotenv) format. ## Server Install Install the module you Perl module path. 1. load module and call sub source_dotenv(); ``` use DotenvSimple; DotenvSimple::source_dotenv('/tmp/.env'); ``` 2. Here's a sample `/tmp/.env`, can follow any of the below formats ``` # <--- hashes or comments are ignored # we also ignore export, white spaces and semicolons export DD_DATABASE_NAME = issm_lists_stage; # single and double quotes for values are allowed DD_DATABASE_USER=dev DD_DATABASE_PASSWD=dev DD_DATABASE_HOST='192.168.33.1' DD_DATABASE_PORT='3306'; DD_DATABASE_Type = "mysql"; ``` Refferancing key a key to get teh value from the above `.env` files: `print $ENV{DD_DATABASE_HOST};` output > `192.168.33.1` #### Options Loading dotenv in this order. Once found it will stop searching for dotenv. 1. You pass the path of you dotenv file as a parameter `DotenvSimple::source_dotenv('/tmp/.env');` 2. If you set a Perl accessable enviroment parameter `$ENV{DOTENV_FILE}` the subroutine will use the value of this vaiable. Use case would be to define this in apache vhost configs like so ``` ... SetEnv DOTENV_FILE /tmp/.env ... ``` 3. Generally when using Apache, the document root variable `$ENV{DOCUMENT_ROOT}`, is loaded into perl. if using HTTPD it will also search for `.env` in your document root.