| Line | |
|---|
| 1 | package PluginManager::Util; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use vars qw(@EXPORT_OK @ISA); |
|---|
| 5 | require Exporter; |
|---|
| 6 | @EXPORT_OK = qw(debug scrub_path); |
|---|
| 7 | @ISA = qw(Exporter); |
|---|
| 8 | |
|---|
| 9 | ##################################################################### |
|---|
| 10 | # UTILITY SUBROUTINES |
|---|
| 11 | ##################################################################### |
|---|
| 12 | |
|---|
| 13 | sub debug { |
|---|
| 14 | my $err = shift; |
|---|
| 15 | my $mark = shift || '>'; |
|---|
| 16 | print STDERR "$mark $err\n" if $MT::Plugin::PluginManager::DEBUG; |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | sub scrub_path { |
|---|
| 20 | my ($path) = @_; |
|---|
| 21 | require File::Spec; |
|---|
| 22 | my @dirs = File::Spec->splitdir($path); |
|---|
| 23 | my @newdirs; |
|---|
| 24 | foreach (@dirs) { |
|---|
| 25 | if ($_ eq '..') { |
|---|
| 26 | pop @newdirs; |
|---|
| 27 | } elsif ($_ eq '.') { |
|---|
| 28 | # do nothing |
|---|
| 29 | } else { |
|---|
| 30 | push @newdirs,$_; |
|---|
| 31 | } |
|---|
| 32 | } |
|---|
| 33 | return File::Spec->catdir(@newdirs); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | 1; |
|---|