☞ | ![]() ![]() |
61 |
92 if ( ref $o eq 'CODE' ) { 93 $o->( $item, $action, @params ); 95 else { 96 $o->update( $item, $action, @params );
This is so that you can use a plain subroutine as an observer
my $a = Alarm->new; $a->add_observer(\&complain); $a->notify_observers("I like pie!"); # Calls complain()
I considered eliminating the special case
Have add_observer convert the raw coderef to an object:
if (ref $o eq "CODE") { $o = Class::Observer::CODEObserver->new($o); }
I thought for sure this would be simpler
I was wrong
The special case moved from notify_observers to add_observer
(No net benefit)
Deletion became impossibly complicated
Try it both ways
You won't know unless you try
☞ | ![]() |
☞ |