3 # This spec file was automatically generated by cpan2rpm [ver: 2.027]
4 # The following arguments were used:
5 # --spec-only --version=1.04 '--author=Fred Moyer' Class-Factory-1.04.tar.gz
6 # For more information on cpan2rpm please visit: http://perl.arix.com/
9 %define pkgname Class
-Factory
10 %define filelist
%{pkgname}-%{version}-filelist
11 %define NVR
%{pkgname}-%{version}-%{release}
14 name
: perl
-Class
-Factory
15 summary
: Class
-Factory
- Useful base class
for factory classes
19 packager
: Arix International
<cpan2rpm@arix.com
>
21 group
: Applications
/CPAN
22 url
: http
://www.cpan.org
23 buildroot
: %{_tmppath}/%{name}-%{version}-%
(id
-u
-n
)
25 prefix
: %
(echo %{_prefix})
26 source: Class
-Factory
-1.04.tar.gz
29 This is a simple module that factory classes can use to generate new
30 types of objects on the fly
, providing a consistent interface to
31 common groups of objects.
33 Factory classes are used when you have different implementations
for
34 the same
set of tasks but may not know
in advance what implementations
35 you will be using. Configuration files are a good example of
36 this. There are four basic operations you would want to
do with any
37 configuration
: read the file
in, lookup a value
, set a value
, write
38 the file out. There are also many different types of configuration
39 files
, and you may want users to be able to provide an implementation
40 for their own home
-grown configuration format.
42 With a factory class this is easy. To create the factory class
, just
43 subclass "Class
::Factory" and create an interface
for your
44 configuration serializer. "Class
::Factory" even provides a simple
45 constructor
for you. Here's a sample interface and our two built
-in
48 package My
::ConfigFactory
;
51 use base qw
( Class
::Factory
);
53 sub
read { die "Define
read() in implementation"
}
54 sub write
{ die "Define write
() in implementation"
}
55 sub get
{ die "Define get
() in implementation"
}
56 sub
set { die "Define
set() in implementation"
}
58 __PACKAGE__
->add_factory_type
( ini
=> 'My
::IniReader'
);
59 __PACKAGE__
->add_factory_type
( perl
=> 'My
::PerlReader'
);
63 And
then users can add their own subclasses
:
65 package My
::CustomConfig
;
68 use base qw
( My
::ConfigFactory
);
71 my
( $self
, $filename
, $params
) = @_
;
72 if ( $params
->{base_url
} ) {
73 $self
->read_from_web
( join
( '
/'
, $params
->{base_url
}, $filename
) );
76 $self
->read( $filename
);
81 sub
read { ... implementation to
read a file ...
}
82 sub write
{ ... implementation to write a file ...
}
83 sub get
{ ... implementation to get a value ...
}
84 sub
set { ... implementation to
set a value ...
}
86 sub read_from_web
{ ... implementation to
read via http ...
}
88 # Now register my type with the factory
90 My
::ConfigFactory
->add_factory_type
( 'mytype'
=> __PACKAGE__
);
94 (You may not wish to
make your factory the same as your interface
, but
95 this is an abbreviated example.
)
97 So now users can use the custom configuration with something like
:
102 use My
::ConfigFactory
;
103 use My
::CustomConfig
; # this adds the factory type 'custom'...
105 my $config
= My
::ConfigFactory
->new
( 'custom'
, 'myconf.dat'
);
106 print "Configuration is a
: "
, ref
( $config
), "\n"
;
110 Configuration is a My
::CustomConfig
112 And they can even add their own
:
114 My
::ConfigFactory
->register_factory_type
( 'newtype'
=> 'My
::New
::ConfigReader'
);
116 This might not seem like a very big win
, and
for small standalone
117 applications probably isn't. But when you develop large applications
118 the "
(add|register
)_factory_type
()" step will almost certainly be
119 done at application initialization
time, hidden away from the eyes of
120 the application developer. That developer will only know that she can
121 access the different object types as
if they are part of the system.
123 As you see
in the example above implementation
for subclasses is very
124 simple
-- just add "Class
::Factory" to your inheritance tree and you
128 # This package was generated automatically with the cpan2rpm
129 # utility. To get this software or for more information
130 # please visit: http://perl.arix.com/
134 %setup -q
-n
%{pkgname}-%{version}
135 chmod
-R u
+w
%{_builddir}/%{pkgname}-%{version}
138 grep
-rsl '^
#!.*perl' . |
139 grep
-v '.bak$' |xargs
--no
-run
-if-empty \
140 %__perl -MExtUtils
::MakeMaker
-e 'MY
->fixin
(@ARGV
)'
141 CFLAGS
="$RPM_OPT_FLAGS"
142 %{__perl} Makefile.PL `%{__perl} -MExtUtils::MakeMaker -e ' print qq|PREFIX=%{buildroot}%{_prefix}|
if \$ExtUtils
::MakeMaker
::VERSION
=~
/5\
.9[1-6]|
6\
.0[0-5]/ '`
149 [ "
%{buildroot}" != "/" ] && rm -rf %{buildroot}
151 %{makeinstall} `%{__perl} -MExtUtils::MakeMaker -e ' print \$ExtUtils::MakeMaker::VERSION <= 6.05 ? qq|PREFIX=%{buildroot}%{_prefix}| : qq|DESTDIR=%{buildroot}| '`
153 cmd
=/usr
/share
/spec
-helper
/compress_files
154 [ -x $cmd
] || cmd
=/usr
/lib
/rpm
/brp
-compress
158 if [ -e
/etc
/SuSE
-release
-o
-e
/etc
/UnitedLinux
-release
]
160 %{__mkdir_p} %{buildroot}/var
/adm
/perl
-modules
161 %{__cat} `find %{buildroot} -name "perllocal.pod"` \
162 |
%{__sed} -e s+%{buildroot}++g \
163 > %{buildroot}/var/adm/perl-modules/%{name}
166 # remove special files
167 find
%{buildroot} -name "perllocal.pod" \
168 -o
-name ".packlist" \
172 # no empty directories
173 find
%{buildroot}%{_prefix} \
175 -exec rmdir {} \
; 2>/dev
/null
177 %{__perl} -MFile
::Find
-le '
178 find
({ wanted
=> \
&wanted
, no_chdir
=> 1}, "
%{buildroot}"
);
179 print "
%doc Changes README"
;
180 for my $x
(sort @
dirs, @files
) {
181 push @ret
, $x unless indirs
($x
);
183 print join "\n"
, sort @ret
;
188 local $_
= $File
::Find
::name
;
189 my $f
= $_
; s|^\Q
%{buildroot}\E||
;
190 return unless length
;
191 return $files
[@files
] = $_
if -f $f
;
194 /\Q$d\E
/ && return for reverse sort @INC
;
195 $d
=~
/\Q$_\E
/ && return
196 for qw|
/etc
%_prefix/man
%_prefix/bin
%_prefix/share|
;
203 $x
=~
/^\Q$_\E\
// && $x ne $_
&& return 1 for @
dirs;
207 [ -z
%filelist ] && {
208 echo "ERROR
: empty
%files listing"
213 [ "
%{buildroot}" != "/" ] && rm -rf %{buildroot}
216 %defattr(-,root
,root
)
219 * Thu Nov
23 2006 root@dca02