/[cvs]/nfo/perl/libs/DesignPattern/Bridge.pm
ViewVC logotype

Contents of /nfo/perl/libs/DesignPattern/Bridge.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Mon Dec 16 19:57:12 2002 UTC (21 years, 5 months ago) by joko
Branch: MAIN
Changes since 1.2: +46 -6 lines
+ sub unload

1 ## --------------------------------------------------------------------------------
2 ## $Id: Bridge.pm,v 1.2 2002/12/15 02:06:15 joko Exp $
3 ## --------------------------------------------------------------------------------
4 ## $Log: Bridge.pm,v $
5 ## Revision 1.2 2002/12/15 02:06:15 joko
6 ## + feature to be able to specify module in non-perl-style when loading plugins: e.g. $process->load('Setup/Storage')
7 ##
8 ## Revision 1.1 2002/12/13 21:46:29 joko
9 ## + initial check-in
10 ##
11 ## --------------------------------------------------------------------------------
12
13
14 package DesignPattern::Bridge;
15
16 use strict;
17 use warnings;
18
19 use base qw( DesignPattern::Object );
20
21 use Data::Dumper;
22
23 ## ======== object inheritance ========
24
25 # TODO:
26 # - this is no inheritance and it doesn't have to be
27 # - implement this module as a bridge to its sub-modules
28 # - use the BridgePattern (http://c2.com/cgi/wiki?BridgePattern)
29 # Using patterns was already successfully done with Data::Storage::Handler
30 # by implementing the AdapterPattern (http://c2.com/cgi/wiki?AdapterPattern)
31 # with Perl's AUTOLOAD-mechanism
32 # - try to use Perl's "tie" command to implement this functionality here instead of using AUTOLOAD!
33 # - sub getChildNodes
34 # - sub run
35
36 # get logger instance
37 my $logger = Log::Dispatch::Config->instance;
38
39 my $meta;
40
41 ## ======== object constructor ========
42 sub new {
43 my $invocant = shift;
44 my $class = ref($invocant) || $invocant;
45 my @args = ();
46 @_ && (@args = @_);
47 $logger->debug( __PACKAGE__ . "->new(@args)" );
48 my $self = { @_ };
49 #print "class: $class", "\n";
50 bless $self, $class;
51 ##if (my $bizWorks = shift) {
52 ##$self->boot($bizWorks);
53 ##}
54
55 return $self;
56 }
57
58
59 ## ======== method overrider ========
60 sub AUTOLOAD2 {
61
62 my $self = shift;
63 our $AUTOLOAD;
64
65 ##print "AUTOLOAD\n";
66
67 my $method = $AUTOLOAD;
68 $method =~ s/^.*:://;
69
70 $logger->debug( __PACKAGE__ . "->" . $method . "(@_)" . " (AUTOLOAD called, not dispatched)" );
71
72 ## ->DESTROY would - if not declared - trigger an AUTOLOAD also
73 return if $method =~ m/::DESTROY$/;
74
75 ## if ($self->_filter_AUTOLOAD($method)) {
76 ## $self->_accessStorage();
77 ## $self->{STORAGEHANDLE}->$method(@_);
78 ## }
79
80 }
81
82 sub _getPluginPackage {
83 my $self = shift;
84 my $modulename_load = shift;
85
86 # substitute slashes through double double-colons to load modules perl-style
87 $modulename_load =~ s/\//::/g;
88
89 # build full package name
90 my $self_classname = ref $self;
91 my $package = $self_classname . '::' . $modulename_load;
92 return $package;
93 }
94
95 sub load {
96
97 my $self = shift;
98 my $modulename_load = shift;
99
100 my $package = $self->_getPluginPackage($modulename_load);
101
102 if ($meta->{loaded}->{$package}) {
103 return 1;
104 }
105
106 $logger->info( __PACKAGE__ . "->load: $package" );
107
108 # this is the module testing phase - use mixin doesn't seem to propagate errors by default
109 eval("use $package;");
110 if ($@) {
111 $meta->{loaded}->{$package} = 0;
112 # include caller information
113 my @caller = caller;
114 my $caller_msg = $caller[1] . ':' . $caller[2];
115 $logger->error( __PACKAGE__ . "->load: $@ ($caller_msg)" );
116 }
117
118 #print "ref-1: ", ref $self, "\n";
119 #print "ref-2: ", ref $self::SUPER, "\n";
120
121 # V1:
122 #bless $self, $package;
123
124 # V2:
125 # switch into foreign package and mixin plugin-module
126 my $self_classname = ref $self;
127 eval("package $self_classname; use mixin '$package';");
128 #eval("use mixin_all '$package';");
129 if ($@) {
130 $meta->{loaded}->{$package} = 0;
131 $logger->error( __PACKAGE__ . "->load: $@" );
132 } else {
133 $meta->{loaded}->{$package} = 1;
134 }
135
136 return 1;
137
138 }
139
140 sub unload {
141
142 my $self = shift;
143 my $modulename_unload = shift;
144
145 my $package = $self->_getPluginPackage($modulename_unload);
146
147 if ($meta->{loaded}->{$package}) {
148 $meta->{loaded}->{$package} = 0;
149 my $where = __PACKAGE__ . ':' . __LINE__;
150 $logger->debug( __PACKAGE__ . "->unload: FIXME: DESTROY object is not implemented at '$where'." );
151 }
152
153 }
154
155
156 sub boot {
157 my $self = shift;
158 $self->_abstract_function('boot');
159 }
160
161 1;

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