App-Env

 view release on metacpan or  search on metacpan

lib/App/Env/_Util.pm  view on Meta::CPAN

package App::Env::_Util;

# ABSTRACT: Utilities

use v5.10;
use strict;
use warnings;

our $VERSION = '1.05';

# need to distinguish between a non-existent module
# and one which has compile errors.
use Module::Find qw( );
use List::Util 1.33 'any';
use Params::Validate ();

#-------------------------------------------------------

sub croak {
    require Carp;
    goto &Carp::croak;
}

#-------------------------------------------------------

# environment cache
my %Cache;

sub getCacheEntry    { return $Cache{ $_[0] }; }
sub setCacheEntry    { $Cache{ $_[0] } = $_[1]; }
sub deleteCacheEntry { delete $Cache{ $_[0] } }
sub existsCacheEntry { return exists $Cache{ $_[0] }; }
sub is_CacheEmpty    { keys %Cache == 0 }

sub uncache {
    my %opt = Params::Validate::validate(
        @_,
        {
            All     => { default  => undef, type => Params::Validate::SCALAR },
            App     => { default  => undef, type => Params::Validate::SCALAR },
            Site    => { optional => 1,     type => Params::Validate::SCALAR },
            CacheID => { default  => undef, type => Params::Validate::SCALAR },
        } );

    if ( $opt{All} ) {
        delete $opt{All};
        croak( "can't specify All option with other options\n" )
          if any { defined } values %opt;
        %Cache = ();
    }

    elsif ( defined $opt{CacheID} ) {
        my $cacheid = delete $opt{CacheID};
        croak( "can't specify CacheID option with other options\n" )
          if any { defined } values %opt;

        delete $Cache{$cacheid};
    }
    else {
        croak( "must specify App or CacheID options\n" )
          unless defined $opt{App};

        # don't use normal rules for Site specification as we're trying
        # to delete a specific one.
        delete $Cache{ modulename( app_env_site( exists $opt{Site} ? ( $opt{Site} ) : () ), $opt{App} ) };
    }

    return;
}

#-------------------------------------------------------

my %existsModule;

sub loadModuleList {
    %existsModule = ();

    for my $path ( Module::Find::findallmod( 'App::Env' ) ) {
        # greedy match picks up full part of path
        my ( $base, $app ) = $path =~ /^(.*)::(.*)/;

        # store lowercased module
        $existsModule{ $base . q{::} . lc $app } = $path;
    }

    return;
}

sub existsModule {
    my ( $path ) = @_;

    # reconstruct path with lowercased application name.
    # greedy match picks up full part of path
    my ( $base, $app ) = $path =~ /^(.*)::(.*)/;
    $path = $base . q{::} . lc $app;



( run in 1.127 second using v1.01-cache-2.11-cpan-39bf76dae61 )