Grips-Gripsrc
view release on metacpan or search on metacpan
# Grips::Gripsrc.pm
#
# Copyright (c) 2002 DIMDI <tarek.ahmed@dimdi.de>. All rights reserved.
#
# This module is free software; you can redistribute it and/or modify it under
# the same terms as Perl itself, i.e. under the terms of either the GNU General
# Public License or the Artistic License, as specified in the F<LICENCE> file.
package Grips::Gripsrc;
use Carp;
use strict;
use FileHandle;
use vars qw($VERSION);
$VERSION = "0.01"; # $Id: Gripsrc.pm,v 1.2 2003-02-04 12:19:08 ahmed Exp $
my %gripsrc = ();
sub _readrc
{
my $host = shift;
my($home,$file);
if($^O eq "MacOS") {
$home = $ENV{HOME} || `pwd`;
chomp($home);
$file = ($home =~ /:$/ ? $home . "gripsrc" : $home . ":gripsrc");
} else {
# Some OS's don't have `getpwuid', so we default to $ENV{HOME}
$home = eval { (getpwuid($>))[7] } || $ENV{HOME};
$file = $home . "/.gripsrc";
}
my $fh;
local $_;
$gripsrc{default} = undef;
# OS/2 and Win32 do not handle stat in a way compatable with this check :-(
unless($^O eq 'os2'
|| $^O eq 'MSWin32'
|| $^O eq 'MacOS'
|| $^O =~ /^cygwin/)
{
my @stat = stat($file);
if(@stat)
{
if($stat[2] & 077)
{
carp "Bad permissions: $file";
return;
}
if($stat[4] != $<)
{
carp "Not owner: $file";
return;
}
}
}
if($fh = FileHandle->new($file,"r"))
{
my($mach,$macdef,$tok,@tok) = (0,0);
while(<$fh>)
{
undef $macdef if /\A\n\Z/;
if($macdef)
{
push(@$macdef,$_);
next;
}
s/^\s*//;
chomp;
push(@tok, $+)
while(length && s/^("([^"]*)"|(\S+))\s*//);
TOKEN:
while(@tok)
{
if($tok[0] eq "default")
{
shift(@tok);
$mach = bless {};
$gripsrc{default} = [$mach];
next TOKEN;
( run in 1.256 second using v1.01-cache-2.11-cpan-a49fcb8fa48 )