/[cvs]/nfo/perl/libs/Data/Mungle/Code/Symbol.pm
ViewVC logotype

Contents of /nfo/perl/libs/Data/Mungle/Code/Symbol.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Fri Jun 6 03:25:42 2003 UTC (21 years ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +24 -2 lines
+ sub alias_simple

1 ## ---------------------------------------------------------------------------
2 ## $Id: Symbol.pm,v 1.3 2003/05/13 07:33:38 joko Exp $
3 ## ---------------------------------------------------------------------------
4 ## $Log: Symbol.pm,v $
5 ## Revision 1.3 2003/05/13 07:33:38 joko
6 ## enhanced: now can get symbols as list or hash
7 ##
8 ## Revision 1.2 2003/03/27 15:17:03 joko
9 ## namespace fixes for Data::Mungle::*
10 ##
11 ## Revision 1.1 2003/01/22 17:59:22 root
12 ## + refactored from Mail::Audit::Dispatch
13 ##
14 ## ---------------------------------------------------------------------------
15
16
17 =pod
18
19 =head1 TODO
20
21 o Investigate: Could this functionality be completely replaced through CPAN's
22 - Symbol.pm?
23 - Alias.pm?
24
25
26 =cut
27
28
29 package Data::Mungle::Code::Symbol;
30
31 use strict;
32 use warnings;
33
34 require Exporter;
35 our @ISA = qw( Exporter );
36 our @EXPORT_OK = qw(
37 export_symbols
38 alias_simple
39 );
40
41
42 use Data::Mungle::Code::Ref qw( get_coderef );
43 use Symbol;
44
45 sub export_symbols {
46 my $symbols = shift;
47 my $mixinPackage = shift;
48 my $callPackage = shift;
49 $callPackage ||= __PACKAGE__;
50 if (ref $symbols eq 'ARRAY') {
51 foreach (@$symbols) {
52 {
53 no strict 'refs';
54 my $newName = $mixinPackage . '::' . $_;
55 *{$newName} = get_coderef($callPackage, $_);
56 }
57 }
58
59 } elsif (ref $symbols eq 'HASH') {
60 foreach (keys %$symbols) {
61 {
62 no strict 'refs';
63 my $newName = $mixinPackage . '::' . $symbols->{$_};
64 *{$newName} = get_coderef($callPackage, $_);
65 }
66 }
67
68 }
69 }
70
71 # Qualifies a variable identified by package name and variable
72 # name into a valid symbol, resolves that symbol and stores the
73 # result (a reference to this variable) into the designated target (slot).
74 sub alias_simple {
75 my $rule = shift;
76 my $target = $rule->{slot};
77 my $name = $rule->{alias};
78 my $sym = qualify($rule->{var_name}, $rule->{var_pkg});
79 {
80 no strict 'refs';
81 $target->{$name} = ${$sym};
82 }
83 }
84
85 1;
86 __END__

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed