WWW-Autosite

 view release on metacpan or  search on metacpan

lib/WWW/Autosite.pm  view on Meta::CPAN

	};	

	for ( keys %$ext ){
		$abs=~$ext->{$_} or next;
		$type = $_ and last;
	}
	
	$type or $type = 'dir' if -d $abs;

	my $pse= pseudomime($abs);
	$type = $pse if exists $ext->{$pse};

	$type ||='default';

	return $type;
}

=head2 icon()

argument is abs path to file, returns icon name for resource.

=cut



sub script_dir {
	my $script_dir = $0; 
	$script_dir=~s/\/[^\/]+$// or $script_dir = './';
#	if ($script_dir _ ){ # i thought $0 would always hold full path to the script being executed./. nope// not on bsd GRRRR!!
#		$script_dir = './';
#	}	
	return $script_dir;
}

=head2 script_dir()

Accepts no arguments.
Returns absolute location of running script.
I said absolute 'location', which is the directory it resides in.

=cut

sub slurp {
   my $abs_path = shift;   
	my $content = do { local( @ARGV, $/ ) = $abs_path; <> } ;
   return $content;
}

=head2 slurp()

argument is abs path to a -t text file
returns content

	my $src - slurp('/path/to/default.css');
	
=cut

sub abs_path_n {
	my $absPath = shift;
	return $absPath if $absPath =~ m{^/$};
   my @elems = split m{/}, $absPath;
   my $ptr = 1;
   while($ptr <= $#elems)
    {
        if($elems[$ptr] eq q{})
        {
            splice @elems, $ptr, 1;
        }
        elsif($elems[$ptr] eq q{.})
        {
            splice @elems, $ptr, 1;
        }
        elsif($elems[$ptr] eq q{..})
        {
            if($ptr < 2)
            {
                splice @elems, $ptr, 1;
            }
            else
            {
                $ptr--;
                splice @elems, $ptr, 2;
            }
        }
        else
        {
            $ptr++;
        }
    }
    return $#elems ? join q{/}, @elems : q{/};

	# by JohnGG 
	# http://perlmonks.org/?node_id=603442	
}

=head2 abs_path_n()

just like Cwd::abs_path() but, does not resolve symlinks. Just cleans up the path.
argument is an abs path.

=cut


sub get_meta {
	my $abs_path = shift; $abs_path or croak('get_meta() needs abs path as argument');

	if( -f $abs_path.'.meta'){
			my $meta = YAML::LoadFile( $abs_path.'.meta' );   
			return $meta;
	}
	# try hidden
	my $abs_meta = $abs_path;
	$abs_meta=~s/\/([^\/]+)$/.$1.meta/;
	if (-f $abs_meta) {
			my $meta = YAML::LoadFile( $abs_meta );
			return $meta;
	}
	return;
}

=head2 get_meta()



( run in 1.162 second using v1.01-cache-2.11-cpan-71847e10f99 )