annotate Lib/IMPL/Code/Loader.pm @ 170:b88b7fe60aa3

refactoring
author sourcer
date Tue, 24 May 2011 01:11:16 +0400
parents 76515373dac0
children 4d0e1962161c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
165
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
1 package IMPL::Code::Loader;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
2 use strict;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
3 use warnings;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
4
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
5 my %packages;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
6
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
7 sub Provide {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
8 my ($self,$package) = @_;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
9
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
10 my ($declaringPackage,$file) = caller();
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
11 $packages{$package} = { declaringPackage => $declaringPackage, file => $file, evidence => 'provide' };
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
12 }
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
13
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
14 sub Require {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
15 my ($self,$package) = @_;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
16
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
17 return 1 if $packages{$package};
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
18
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
19 if (my $file = $INC{$package}) {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
20 $packages{$package} = { file => $file, evidence => 'inc' };
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
21 return 1;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
22 }
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
23
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
24 undef $@;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
25
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
26 if ( eval "require $package; 1;" and not $packages{$package}) {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
27 $packages{$package} = { file => $INC{$package}, evidence => 'inc' };
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
28 };
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
29
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
30 die $@ if $@ and not $!;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
31 }
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
32
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
33 1;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
34