Config-IOD-Reader

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN



0.28    2016-10-07  Released-By: PERLANCAR

	- For now, skip the whole t/encoding_path.t on Windows, because
	  File::HomeDir->users_home() is not implemented on Windows.


0.27    2016-10-07  Released-By: PERLANCAR

        - Derp, forgot to replace usage of getpwuid() in lib/, only in t/.

        - Replace PERLANCAR::File::HomeDir with File::HomeDir for now, as
          PERLANCAR::File::HomeDir currently cannot return other user's home
          directory.


0.26    2016-10-07  Released-By: PERLANCAR

        - Replace getpwuid() with checking USERNAME/USER and
          PERLANCAR::File::HomeDir, to make it work on Windows [GH#1].


0.25    2016-09-25  Released-By: PERLANCAR

	- Revert from using JSON::MaybeXS to JSON because JSON::MaybeXS is
	  currently not depakable (hard dependency to XS module
	  Cpanel::JSON::XS).


lib/Config/IOD/Base.pm  view on Meta::CPAN

    }
    # should not be reached
}

sub _get_my_user_name {
    if ($^O eq 'MSWin32') {
        return $ENV{USERNAME};
    } else {
        return $ENV{USER} if $ENV{USER};
        my @pw;
        eval { @pw = getpwuid($>) };
        return $pw[0] if @pw;
    }
}

# borrowed from PERLANCAR::File::HomeDir 0.04
sub _get_my_home_dir {
    if ($^O eq 'MSWin32') {
        # File::HomeDir always uses exists($ENV{x}) first, does it want to avoid
        # accidentally creating env vars?
        return $ENV{HOME} if $ENV{HOME};
        return $ENV{USERPROFILE} if $ENV{USERPROFILE};
        return join($ENV{HOMEDRIVE}, "\\", $ENV{HOMEPATH})
            if $ENV{HOMEDRIVE} && $ENV{HOMEPATH};
    } else {
        return $ENV{HOME} if $ENV{HOME};
        my @pw;
        eval { @pw = getpwuid($>) };
        return $pw[7] if @pw;
    }

    die "Can't get home directory";
}

# borrowed from PERLANCAR::File::HomeDir 0.05, with some modifications
sub _get_user_home_dir {
    my ($name) = @_;

    if ($^O eq 'MSWin32') {
        # not yet implemented
        return undef; ## no critic: Subroutines::ProhibitExplicitReturnUndef
    } else {
        # IF and only if we have getpwuid support, and the name of the user is
        # our own, shortcut to my_home. This is needed to handle HOME
        # environment settings.
        if ($name eq getpwuid($<)) {
            return _get_my_home_dir();
        }

      SCOPE: {
            my $home = (getpwnam($name))[7];
            return $home if $home and -d $home;
        }

        return undef; ## no critic: Subroutines::ProhibitExplicitReturnUndef
    }



( run in 0.362 second using v1.01-cache-2.11-cpan-8d75d55dd25 )