package Window;

my $_id = 1;
sub new { bless { _id => $_id++ }, $_[0] }

use Class::Multimethods;

multimethod receive_event
	=> ("Window", "Event", "Mode")
		=> sub { print	"Window $_[0]->{_id} can't handle a ",
			ref($_[1]), " event in ", ref($_[2]), " mode\n" };

multimethod receive_event
	=> ("Window", "Event", "OffMode")
		=> sub { print "No window operations available in OffMode\n" };

multimethod receive_event
	=> ("ModalWindow", "ReshapeEvent", "Mode")
		=> sub { print "Modal windows can't handle reshape events\n" };

multimethod receive_event
	=> ("ModalWindow", "AcceptEvent", "Mode")
		=> sub { print "Modal window $_[0]->{_id} accepts!\n" };

multimethod receive_event
	=> ("ModalWindow", "AcceptEvent", "OffMode")
		=> sub { print "Modal window $_[0]->{_id} can't accept in OffMode!\n" };

multimethod receive_event
	=> ("MovableWindow", "MoveEvent", "OnMode")
		=> sub { print "Moving window $_[0]->{_id}!\n" };

multimethod receive_event
	=> ("ResizableWindow", "ResizeEvent", "OnMode")
		=> sub { print "Resizing window $_[0]->{_id}!\n" };

multimethod receive_event
	=> ("ResizableWindow", "MoveAndResizeEvent", "OnMode")
		=> sub { print "Moving and resizing window $_[0]->{_id}!\n" };

package ModalWindow;	@ISA = qw( Window );
package MovableWindow;	@ISA = qw( Window );
package ResizableWindow;	@ISA = qw( MovableWindow );

package Event;
package ReshapeEvent;	@ISA = qw( Event );
package AcceptEvent;	@ISA = qw( Event );
package MoveEvent;	@ISA = qw( ReshapeEvent );
package ResizeEvent;	@ISA = qw( ReshapeEvent );
package MoveAndResizeEvent;	@ISA = qw( MoveEvent ResizeEvent );

package Mode;
package OnMode;	@ISA = qw( Mode );
package ModalMode;	@ISA = qw( Mode );
package OffMode;	@ISA = qw( Mode );

=for later

# CREATE SOME WINDOWS...

	@window = (
			ModalWindow->new(),
			MovableWindow->new(),
			ResizableWindow->new(),
		  );

# ...AND SOME COMMANDS...

	@event = (
			bless ( {}, MoveEvent ),
			bless ( {}, ResizeEvent ),
			bless ( {}, MoveAndResizeEvent ),
			bless ( {}, AcceptEvent ),
			bless ( {}, ReshapeEvent ),
		   );

# ...AND SOME MODES...

	@mode = (
			bless ( {}, OffMode ),
			bless ( {}, ModalMode ),
			bless ( {}, OnMode ),
		   );


# AND INTERACT THEM ALL...

	for my $w ( @window )
	{
		for my $e ( @event )
		{
			for my $m ( @mode )
			{
			print "receive_event(",ref($w),",",ref($e),",",ref($m),")...\n\t";
			eval { $w->receive_event($e,$m) } or print $@;
			}
		}
	}

<>;
=cut

Class::Multimethods::analyse
("receive_event",
    [
	[ModalWindow, Window, MovableWindow, ResizableWindow],
	[Event, ReshapeEvent, MoveEvent, MoveAndResizeEvent],
	[OnMode, Mode]
    ])


#########################################################################
#                                                                       #
#  Copyright (C) 1999 by Manning Publications Co. All Rights Reserved.  #
#                                                                       #
#  This code is free software. It may be used, redistributed            #
#  and/or modified under the terms of the Perl Artistic License         #
#  (see http://www.perl.com/perl/misc/Artistic.html).                   #
#                                                                       #
#########################################################################

