File: Without.pm

package info (click to toggle)
libemail-send-perl 2.198-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 300 kB
  • ctags: 76
  • sloc: perl: 523; makefile: 8
file content (40 lines) | stat: -rw-r--r-- 1,001 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use strict;

package Without;

use File::Path ();
use File::Spec ();
use File::Temp ();
use Symbol ();

my $tempdir;
BEGIN { $tempdir = File::Temp::tempdir(DIR => 't', CLEANUP => 1); }
use lib $tempdir;

sub import {
  my ($self, @modules) = @_;

  foreach my $module (@modules) {
    my @parts = split /::/, $module;
    my $pm_file = pop(@parts) . '.pm';
    my $pm_path = File::Spec->catdir(@parts); 
    my $path = @parts ? File::Spec->catdir($tempdir, $pm_path) : $tempdir;

    File::Path::mkpath($path, 0, 0755) unless -d $path;
    
    my $file = File::Spec->catfile($path, $pm_file);

    return if -e $file;
    
    my $new_pm_fh = Symbol::gensym;
    open $new_pm_fh, ">$file" or die "couldn't open $file for output: $!";
    print $new_pm_fh "die;\n"   or die "couldn't write to $file: $!";
    close $new_pm_fh          or die "error closing $file: $!";

    my $pm_relname =
      File::Spec->abs2rel( File::Spec->catfile($pm_path, $pm_file) );
    delete $INC{$pm_relname};
  }
}

1;