r9073 - in /trunk/libclass-factory-perl: Changes MANIFEST META.yml README debian/changelog lib/Class/Factory.pm t/MyFlexibleBand.pm t/factory.t
gregoa-guest at users.alioth.debian.org
gregoa-guest at users.alioth.debian.org
Fri Nov 9 15:33:41 UTC 2007
Author: gregoa-guest
Date: Fri Nov 9 15:33:41 2007
New Revision: 9073
URL: http://svn.debian.org/wsvn/?sc=1&rev=9073
Log:
New upstream release.
Added:
trunk/libclass-factory-perl/t/MyFlexibleBand.pm
- copied unchanged from r9072, branches/upstream/libclass-factory-perl/current/t/MyFlexibleBand.pm
Modified:
trunk/libclass-factory-perl/Changes
trunk/libclass-factory-perl/MANIFEST
trunk/libclass-factory-perl/META.yml
trunk/libclass-factory-perl/README
trunk/libclass-factory-perl/debian/changelog
trunk/libclass-factory-perl/lib/Class/Factory.pm
trunk/libclass-factory-perl/t/factory.t
Modified: trunk/libclass-factory-perl/Changes
URL: http://svn.debian.org/wsvn/trunk/libclass-factory-perl/Changes?rev=9073&op=diff
==============================================================================
--- trunk/libclass-factory-perl/Changes (original)
+++ trunk/libclass-factory-perl/Changes Fri Nov 9 15:33:41 2007
@@ -1,4 +1,8 @@
Revision history for Perl extension Class::Factory.
+
+1.06 Tue Nov 6 21:16:07 CET 2007
+ - Added remove_factory_type(), unregister_factory_type() and
+ get_factory_type_for(). Marcel Gruenauer <marcel at cpan.org>
1.05 Thu Feb 1 22:57:21 PST 2007
- Added method get_registered_class(), suggested by
Modified: trunk/libclass-factory-perl/MANIFEST
URL: http://svn.debian.org/wsvn/trunk/libclass-factory-perl/MANIFEST?rev=9073&op=diff
==============================================================================
--- trunk/libclass-factory-perl/MANIFEST (original)
+++ trunk/libclass-factory-perl/MANIFEST Fri Nov 9 15:33:41 2007
@@ -7,5 +7,6 @@
t/MyCountryBand.pm
t/MyRockBand.pm
t/MySimpleBand.pm
+t/MyFlexibleBand.pm
META.yml Module meta-data (added by MakeMaker)
Modified: trunk/libclass-factory-perl/META.yml
URL: http://svn.debian.org/wsvn/trunk/libclass-factory-perl/META.yml?rev=9073&op=diff
==============================================================================
--- trunk/libclass-factory-perl/META.yml (original)
+++ trunk/libclass-factory-perl/META.yml Fri Nov 9 15:33:41 2007
@@ -1,7 +1,7 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Class-Factory
-version: 1.05
+version: 1.06
version_from: lib/Class/Factory.pm
installdirs: site
requires:
Modified: trunk/libclass-factory-perl/README
URL: http://svn.debian.org/wsvn/trunk/libclass-factory-perl/README?rev=9073&op=diff
==============================================================================
--- trunk/libclass-factory-perl/README (original)
+++ trunk/libclass-factory-perl/README Fri Nov 9 15:33:41 2007
@@ -40,6 +40,14 @@
# Get a registered class name given it's factory type
my $registered_class = MyFactory->get_registered_class( 'bleededge' );
+
+ # Remove a factory type
+
+ MyFactory->remove_factory_type('custom');
+
+ # Unregister a factory type
+
+ MyFactory->unregister_factory_type('bleededge');
See POD for details
@@ -85,3 +93,7 @@
Sebastian Knapp <giftnuss at netscape.net> contributed the idea for
'get_registered_class()'
+
+Marcel Gruenauer <marcel at cpan.org> contributed the methods
+remove_factory_type() and unregister_factory_type().
+
Modified: trunk/libclass-factory-perl/debian/changelog
URL: http://svn.debian.org/wsvn/trunk/libclass-factory-perl/debian/changelog?rev=9073&op=diff
==============================================================================
--- trunk/libclass-factory-perl/debian/changelog (original)
+++ trunk/libclass-factory-perl/debian/changelog Fri Nov 9 15:33:41 2007
@@ -1,10 +1,11 @@
-libclass-factory-perl (1.05-2) UNRELEASED; urgency=low
+libclass-factory-perl (1.06-1) UNRELEASED; urgency=low
+ * New upstream release.
* debian/control: Added: Vcs-Svn field (source stanza); Vcs-Browser
field (source stanza); Homepage field (source stanza). Removed: XS-
Vcs-Svn fields.
- -- gregor herrmann <gregor+debian at comodo.priv.at> Tue, 09 Oct 2007 22:28:04 +0200
+ -- gregor herrmann <gregor+debian at comodo.priv.at> Fri, 09 Nov 2007 16:32:14 +0100
libclass-factory-perl (1.05-1) unstable; urgency=low
Modified: trunk/libclass-factory-perl/lib/Class/Factory.pm
URL: http://svn.debian.org/wsvn/trunk/libclass-factory-perl/lib/Class/Factory.pm?rev=9073&op=diff
==============================================================================
--- trunk/libclass-factory-perl/lib/Class/Factory.pm (original)
+++ trunk/libclass-factory-perl/lib/Class/Factory.pm Fri Nov 9 15:33:41 2007
@@ -1,10 +1,10 @@
package Class::Factory;
-# $Id: Factory.pm 40 2006-08-02 05:51:40Z cwinters $
+# $Id: Factory.pm 46 2007-11-07 00:06:38Z cwinters $
use strict;
-$Class::Factory::VERSION = '1.05';
+$Class::Factory::VERSION = '1.06';
my %CLASS_BY_FACTORY_AND_TYPE = ();
my %FACTORY_INFO_BY_CLASS = ();
@@ -123,6 +123,48 @@
}
+sub remove_factory_type {
+ my ( $item, @object_types ) = @_;
+ my $class = ref $item || $item;
+
+ for my $object_type (@object_types) {
+ unless ( $object_type ) {
+ $item->factory_error(
+ "Cannot remove factory type from '$class': no type defined"
+ );
+ }
+
+ delete $CLASS_BY_FACTORY_AND_TYPE{ $class }->{ $object_type };
+ }
+}
+
+
+sub unregister_factory_type {
+ my ( $item, @object_types ) = @_;
+ my $class = ref $item || $item;
+
+ for my $object_type (@object_types) {
+ unless ( $object_type ) {
+ $item->factory_error(
+ "Cannot remove factory type from '$class': no type defined"
+ );
+ }
+
+ delete $REGISTER{ $class }->{ $object_type };
+
+ # Also delete from $CLASS_BY_FACTORY_AND_TYPE because if the object
+ # type has already been instantiated, then it will have been processed
+ # by add_factory_type(), thus creating an entry in
+ # $CLASS_BY_FACTORY_AND_TYPE. We can call register_factory_type()
+ # again, but when we try to instantiate an object via
+ # get_factory_class(), it will find the old entry in
+ # $CLASS_BY_FACTORY_AND_TYPE and use that.
+
+ delete $CLASS_BY_FACTORY_AND_TYPE{ $class }->{ $object_type };
+ }
+}
+
+
sub get_loaded_classes {
my ( $item ) = @_;
my $class = ref $item || $item;
@@ -180,6 +222,14 @@
sub get_my_factory_type {
my ( $item ) = @_;
+ $item->get_factory_type_for($item);
+}
+
+
+# Return the type that the factory uses to create a given object or class.
+
+sub get_factory_type_for {
+ my ( $self, $item ) = @_;
my $impl_class = ref( $item ) || $item;
my $impl_info = $FACTORY_INFO_BY_CLASS{ $impl_class };
if ( ref( $impl_info ) eq 'ARRAY' ) {
@@ -246,13 +296,21 @@
my $registered_class = My::Factory->get_registered_class( 'type' );
- # Ask the object created by the factory: Where did I come from?
-
- my $custom_object = My::Factory->new( 'custom' );
- print "Object was created by factory: ",
+ # Ask the object created by the factory: Where did I come from?
+
+ my $custom_object = My::Factory->new( 'custom' );
+ print "Object was created by factory: ",
$custom_object->get_my_factory, " ",
"and is of type: ",
$custom_object->get_my_factory_type;
+
+ # Remove a factory type
+
+ My::Factory->remove_factory_type('perl');
+
+ # Unregister a factory type
+
+ My::Factory->unregister_factory_type('blech');
=head1 DESCRIPTION
@@ -601,6 +659,29 @@
C<factory_log()> message is issued if the type has already been
registered.
+B<remove_factory_type( @object_types )>
+
+Removes a factory type from the factory. This is the opposite of
+C<add_factory_type()>. No return value.
+
+Removing a factory type is useful if a subclass of the factory wants to
+redefine the mapping for the factory type. C<add_factory_type()> doesn't allow
+overriding a factory type, so you have to remove it first.
+
+B<unregister_factory_type( @object_types )>
+
+Unregisters a factory type from the factory. This is the opposite of
+C<register_factory_type()>. No return value.
+
+Unregistering a factory type is useful if a subclass of the factory wants to
+redefine the mapping for the factory type. C<register_factory_type()> doesn't
+allow overriding a factory type, so you have to unregister it first.
+
+B<get_factory_type_for( $class )>
+
+Takes an object or a class name string and returns the factory type that is
+used to construct that class. Returns undef if there is no such factory type.
+
B<get_loaded_classes()>
Returns a sorted list of the currently loaded classes. If no classes
@@ -688,7 +769,7 @@
=head1 COPYRIGHT
-Copyright (c) 2002-2006 Chris Winters. All rights reserved.
+Copyright (c) 2002-2007 Chris Winters. All rights reserved.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
@@ -701,6 +782,8 @@
=head1 AUTHORS
+Fred Moyer <fred at redhotpenguin.com> is the current maintainer.
+
Chris Winters E<lt>chris at cwinters.comE<gt>
Eric Andreychek E<lt>eric at openthought.netE<gt> implemented overridable
@@ -711,3 +794,7 @@
Sebastian Knapp <giftnuss at netscape.net> contributed the idea for
'get_registered_class()'
+
+Marcel Gruenauer <marcel at cpan.org> contributed the methods
+remove_factory_type() and unregister_factory_type().
+
Modified: trunk/libclass-factory-perl/t/factory.t
URL: http://svn.debian.org/wsvn/trunk/libclass-factory-perl/t/factory.t?rev=9073&op=diff
==============================================================================
--- trunk/libclass-factory-perl/t/factory.t (original)
+++ trunk/libclass-factory-perl/t/factory.t Fri Nov 9 15:33:41 2007
@@ -1,7 +1,7 @@
# -*-perl-*-
use strict;
-use Test::More tests => 33;
+use Test::More tests => 39;
use lib qw( ./t ./lib );
@@ -102,4 +102,25 @@
ok( $MySimpleBand::error_msg =~ /^Cannot add factory type 'disco' to class 'MySimpleBand': factory class 'SomeKeyboardGuy' cannot be required:/,
'Generated correct error message when instantiate object with nonexistent class registration' );
+ MySimpleBand->unregister_factory_type('country');
+ MySimpleBand->new( 'country', { band_name => $country_band } );
+ ok( $MySimpleBand::error_msg =~ /^Factory type 'country' is not defined in 'MySimpleBand'/,
+ 'Error message for instantiating after the factory type was unregistered' );
+
+ MySimpleBand->remove_factory_type('rock');
+ MySimpleBand->new( 'rock', { band_name => $rock_band } );
+ ok( $MySimpleBand::error_msg =~ /^Factory type 'rock' is not defined in 'MySimpleBand'/,
+ 'Error message for instantiating after the factory type was removed' );
+
+ $MySimpleBand::log_msg = '';
+ MySimpleBand->add_factory_type( rock => 'MyRockBand' );
+ is( $MySimpleBand::log_msg, '', 'no warning after re-adding factory type');
+
+ is(MySimpleBand->get_factory_type_for('MyRockBand'), 'rock',
+ 'Factory type retrievable for any given class');
+ is(MySimpleBand->get_factory_type_for($rock), 'rock',
+ 'Factory type retrievable for any given object');
+
+ is(MySimpleBand->get_factory_type_for('MyJPopBand'), undef,
+ 'Factory type undef for unknown class');
}
More information about the Pkg-perl-cvs-commits
mailing list