Skip to content

Commit

Permalink
Item14152: Merge commit '8e054779ecd5f3604d45b85b81fd5734b81c5daf' in…
Browse files Browse the repository at this point in the history
…to Item14152

* commit '8e054779ecd5f3604d45b85b81fd5734b81c5daf':
  Item13897: Fixed callbacks registering by Unit::TestApp.
  • Loading branch information
vrurg committed Sep 8, 2016
2 parents c6fa6a2 + 8e05477 commit 56cf018
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ test/unit/MetaTests.pm 0644
test/unit/NetTests.pm 0644
test/unit/PasswordTests.pm 0644
test/unit/PlackViewTests.pm 0644
test/unit/PlackPostTests.pm 0644
test/unit/PluginHandlerTests.pm 0644
test/unit/PrefsTests.pm 0644
test/unit/QueryTests.pm 0644
Expand Down
4 changes: 3 additions & 1 deletion UnitTestContrib/lib/Unit/TestApp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ sub registerCallbacks {
$this->_cbRegistered(1);
}

before BUILD => sub {
around callbacksInit => sub {
my $orig = shift;
my $this = shift;

$this->registerCallbacks;
return $orig->( $this, @_ );
};

around _prepareRequest => sub {
Expand Down
34 changes: 29 additions & 5 deletions core/lib/Foswiki/Aux/Callbacks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ my %_cbNameIndex;

use Moo::Role;

has _registeredCB => (
is => 'rw',
lazy => 1,
default => sub { {} },
);
around BUILD => sub {
my $orig = shift;
my $this = shift;

$this->callbacksInit;
return $orig->( $this, @_ );
};

# Splits full callback name into namespace and short name.
sub _splitCBName {
Expand Down Expand Up @@ -138,6 +140,19 @@ sub _guessCallbackName {

=begin TML
---++ ObjectMethod callbacksInit()
This method is virtual. Can be overriden by classes to which this role has been
applied. It is guaranteed to be called before any actual callback is called by
an object of the class.
=cut

sub callbacksInit {
}

=begin TML
---++ ObjectMethod registerCallback($name, $fn, $userData)
Adds coderef =$fn= to the list of registered handlers of callback =$name=.
Expand Down Expand Up @@ -215,6 +230,15 @@ sub callback {
return;
}

=begin TML
---++ StaticMethod registerCallbackNames($namespace, @cbNames)
Registers callback names on name space =$namespace=. Called by =Foswiki::Class=
exported =callback_names=.
=cut

sub registerCallbackNames {
my $namespace = shift;
$namespace = ref($namespace) || $namespace;
Expand Down

0 comments on commit 56cf018

Please sign in to comment.