Skip to content

Commit

Permalink
Item14237: Major changes to Foswiki::Class
Browse files Browse the repository at this point in the history
- options are now defined as -opt
- support for -role option - create a role, not a class
- new API for registering custom sugars
- extension related sugars are now registered by ExtManager
- two new default sugars: roleInit and classInit.
  Basically, it's one function named depending on what is module type.
- callback_names sugar is renamed to callbackNames and is now registered
  by Callbacks role.
- AppObject and Callbacks role are now under Foswiki::Role:: namespace.
  • Loading branch information
vrurg committed May 16, 2018
1 parent 7c2ee11 commit 74b0b63
Show file tree
Hide file tree
Showing 85 changed files with 386 additions and 358 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# See bottom of file for license and copyright information
package Foswiki::Configure::Checkers::Plugins::CommentPlugin::GuestCanComment;
use v5.14;

use Moo;
use Foswiki::Class;
extends qw(Foswiki::Configure::Checker);

sub check {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# See bottom of file for license and copyright information
package Foswiki::Configure::Checkers::Plugins::CommentPlugin::RequiredForSave;
use v5.14;

use Moo;
use Foswiki::Class;
extends qw(Foswiki::Configure::Checker);

sub check {
Expand Down
3 changes: 1 addition & 2 deletions CommentPlugin/lib/Foswiki/Plugins/CommentPlugin/JQuery.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
# See Plugin topic for history and plugin information

package Foswiki::Plugins::CommentPlugin::JQuery;
use v5.14;

use Moo;
use Foswiki::Class;
extends qw( Foswiki::Plugins::JQueryPlugin::Plugin );

around BUILDARGS => sub {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
# See Plugin topic for history and plugin information

package Foswiki::Plugins::ConfigurePlugin::JQuery;
use v5.14;

use Moo;
use namespace::clean;
use Foswiki::Class;
extends qw( Foswiki::Plugins::JQueryPlugin::Plugin );

around BUILDARGS => sub {
Expand Down
2 changes: 1 addition & 1 deletion DBConfigExtension/lib/Foswiki/Extension/DBConfig.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use Try::Tiny;

use Foswiki::FeatureSet;

use Foswiki::Class qw(extension);
use Foswiki::Class -extension;
extends qw(Foswiki::Extension);

use version 0.77; our $VERSION = version->declare(0.1.1);
Expand Down
16 changes: 8 additions & 8 deletions EmptyExtension/lib/Foswiki/Extension/Empty.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ details directly influencing a new extension development.

use Foswiki::FeatureSet;

use Foswiki::Class qw(extension);
use Foswiki::Class -extension;
extends qw(Foswiki::Extension);

=begin TML
Expand Down Expand Up @@ -70,7 +70,7 @@ with the following lines:
<verbatim>
package Foswiki::Extension::<your chosen name>;
use Foswiki::Class qw(extension);
use Foswiki::Class -extension;
extends qw(Foswiki::Extension);
use version 0.77; our $VERSION = version->declare(0.0.1);
Expand Down Expand Up @@ -264,7 +264,7 @@ subroutine to declare pluggable methods:
<verbatim>
package Foswiki::CoreClass;
use Foswiki::Class qw(extensible);
use Foswiki::Class -extensible;
extends qw(Foswiki::Object);
...
Expand All @@ -282,17 +282,17 @@ pluggable someMethod => sub {
Method overriding can only work within properly initialized %WIKITOOLNAME%
application environment. I.e. it requires initialized extensions on application
object. On the other hand not only classes with =%PERLDOC{Foswiki::AppObject}%=
object. On the other hand not only classes with =%PERLDOC{Foswiki::Role::AppObject}%=
role applied can use this feature. This is because
=Foswiki::Util::_ExtensibleRole= implicitly adds =__appObj= attribute to the
class it is applied to. In distinction to =%PERLDOC{"Foswiki::AppObject"
class it is applied to. In distinction to =%PERLDOC{"Foswiki::Role::AppObject"
attr="app"}%= attribute =__appObj= is not required and can remain undefined.
For a non =Foswiki::AppObject= class to get the feature enabled it is mandatory
For a non =Foswiki::Role::AppObject= class to get the feature enabled it is mandatory
to have objects of the class created with =%PERLDOC{"Foswiki::App"
method="create"}%= or =%PERLDOC{"Foswiki::AppObject" method="create"}%= methods.
method="create"}%= or =%PERLDOC{"Foswiki::Role::AppObject" method="create"}%= methods.
For example (consider the above sample and assume that the code below belongs
to a class with =Foswiki::AppObject= role):
to a class with =Foswiki::Role::AppObject= role):
<verbatim>
plugBefore "Foswiki::CoreClass::someMethod" => sub {
Expand Down
5 changes: 1 addition & 4 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/Plugin.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# See bottom of file for license and copyright information
package Foswiki::Plugins::JQueryPlugin::Plugin;
use v5.14;

use Foswiki::Plugins::JQueryPlugin::Plugins ();
use Foswiki::Func ();
Expand All @@ -9,10 +8,8 @@ use Assert;

use constant TRACE => 0;

use Moo;
use namespace::clean;
use Foswiki::Class -app;
extends qw(Foswiki::Object);
with qw(Foswiki::AppObject);

has author => ( is => 'rw', default => 'unknown', );
has css => ( is => 'rw', default => sub { [] }, );
Expand Down
4 changes: 1 addition & 3 deletions JsonRpcContrib/lib/Foswiki/Contrib/JsonRpcContrib/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ use Foswiki::Func ();
use Foswiki::Plugins ();
use constant TRACE => 0; # toggle me

use Moo;
use namespace::clean;
use Foswiki::Class -app;
extends qw(Foswiki::Object);
with qw(Foswiki::AppObject);

has data => (
is => 'rw',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use Assert;
use Compress::Zlib ();
use JSON ();

use Foswiki::Class qw(app);
use Foswiki::Class -app;
extends qw(Foswiki::Object);

use constant TRACE => 0; # toggle me
Expand Down
5 changes: 1 addition & 4 deletions JsonRpcContrib/lib/Foswiki/Contrib/JsonRpcContrib/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
# As per the GPL, removal of this notice is prohibited.

package Foswiki::Contrib::JsonRpcContrib::Server;
use v5.14;

use Try::Tiny;
use Foswiki::Func ();
use Foswiki::Contrib::JsonRpcContrib::Error ();
use Foswiki::Contrib::JsonRpcContrib::Response ();

use Moo;
use namespace::clean;
use Foswiki::Class -app;
extends qw(Foswiki::Object);
with qw(Foswiki::AppObject);

use constant TRACE => 0; # toggle me

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# See bottom of file for license and copyright information
package Foswiki::Configure::Checkers::Extensions::PlainFileStoreContrib::CheckForRCS;
use v5.14;

use Moo;
use Foswiki::Class;
extends qw(Foswiki::Configure::Checker);

my @required = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# See bottom of file for license and copyright information
package Foswiki::Configure::Checkers::Store::PlainFile::Implementation;
use v5.14;

use Moo;
use Foswiki::Class;
extends qw(Foswiki::Configure::Checker);

sub check_current_value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use Try::Tiny;
use Foswiki::ListIterator ();
use Foswiki::Func ();

use Foswiki::Class qw(app);
use Foswiki::Class -app;
extends qw(Foswiki::Object);
with qw(Foswiki::UserMapping);

Expand Down
4 changes: 2 additions & 2 deletions UnitTestContrib/lib/Unit/FoswikiTestRole.pm
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,13 @@ application with =_set_app()= method.
*NOTE* No responsibility is taken if a reference to the application is stored in
any other attribute or object's hash key. To make sure that a instance of your
class is handled properly by this core apply =Foswiki::AppObject= role.
class is handled properly by this core apply =Foswiki::Role::AppObject= role.
See also: =Unit::TestApp=
=cut

# Correct all Foswiki::AppObject to use currently active Foswiki::App object.
# Correct all Foswiki::Role::AppObject to use currently active Foswiki::App object.
# SMELL Hacky but shall be transparent for any derived test case class.
sub _fixupAppObjects {
my $this = shift;
Expand Down
10 changes: 5 additions & 5 deletions UnitTestContrib/lib/Unit/TestApp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use Assert;
use Scalar::Util qw(blessed weaken refaddr);
use Try::Tiny;

use Foswiki::Class qw(callbacks);
use Foswiki::Class -callbacks;
extends qw(Foswiki::App);

=begin TML
Expand All @@ -46,7 +46,7 @@ No =params= are sent to the handler.
=cut

callback_names qw(testPreHandleRequest testPostHandleRequest);
callbackNames qw(testPreHandleRequest testPostHandleRequest);

=begin TML
Expand Down Expand Up @@ -130,13 +130,13 @@ around BUILDARGS => sub {
sub BUILD {
my $this = shift;

# Fixup Foswiki::AppObject descendants which have been cloned from objects
# on another Foswiki::App instance.
# Fixup Foswiki::Role::AppObject descendants which have been cloned from
# objects on another Foswiki::App instance.
foreach my $attr ( keys %$this ) {
if (
blessed( $this->{$attr} )
&& $this->$attr->isa('Foswiki::Object')
&& $this->$attr->does('Foswiki::AppObject')
&& $this->$attr->does('Foswiki::Role::AppObject')
&& ( !defined( $this->$attr->app )
|| ( $this->$attr->app != $this ) )
)
Expand Down
3 changes: 1 addition & 2 deletions UnitTestContrib/test/unit/AccessControlTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use Foswiki::Configure::Dependency ();
# For Anchor test
use Foswiki::UI ();

use Moo;
use namespace::clean;
use Foswiki::Class;
extends 'FoswikiFnTestCase';

my $post11 = 0;
Expand Down
3 changes: 1 addition & 2 deletions UnitTestContrib/test/unit/AdminOnlyAccessControlTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use Assert;
# For Anchor test
use Foswiki::UI ();

use Moo;
use namespace::clean;
use Foswiki::Class;
extends qw(FoswikiFnTestCase);

my $post11 = 0;
Expand Down
4 changes: 1 addition & 3 deletions UnitTestContrib/test/unit/AttrsTests.pm
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package AttrsTests;
use v5.14;

use Foswiki::Attrs();
use Moo;
use namespace::clean;
use Foswiki::Class;
extends qw(FoswikiTestCase);

sub test_isEmpty {
Expand Down
4 changes: 1 addition & 3 deletions UnitTestContrib/test/unit/CacheTests.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package CacheTests;
use v5.14;
use utf8;

use Foswiki();
Expand All @@ -8,8 +7,7 @@ use Foswiki::OopsException();
use Foswiki::PageCache();
use Benchmark qw(:hireswallclock);

use Moo;
use namespace::clean;
use Foswiki::Class;
extends qw(FoswikiFnTestCase);

has testAction => ( is => 'rw', );
Expand Down
6 changes: 3 additions & 3 deletions UnitTestContrib/test/unit/CallbackTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

package CBTest::Provider;

use Foswiki::Class qw(callbacks);
use Foswiki::Class -callbacks;
extends qw(Foswiki::Object);

callback_names qw(testCB);
callbackNames qw(testCB);

sub methodWithCB {
my $this = shift;
Expand All @@ -17,7 +17,7 @@ package CBTest::Handler;

use Scalar::Util qw(weaken);

use Foswiki::Class qw(callbacks);
use Foswiki::Class -callbacks;
extends qw(Foswiki::Object);

sub BUILD {
Expand Down
4 changes: 1 addition & 3 deletions UnitTestContrib/test/unit/ClientTests.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package ClientTests;
use v5.14;

# This is woefully incomplete, but it does at least check that
# LoginManager.pm compiles okay.
Expand All @@ -10,8 +9,7 @@ use Try::Tiny;
use Digest::MD5 qw(md5_hex);
use Scalar::Util qw(blessed);

use Moo;
use namespace::clean;
use Foswiki::Class;
extends qw( FoswikiFnTestCase );

my $agent = $Foswiki::cfg{Register}{RegistrationAgentWikiName};
Expand Down
6 changes: 5 additions & 1 deletion UnitTestContrib/test/unit/ExceptionTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use v5.14;
use Try::Tiny;
use Foswiki::OopsException();
use Foswiki::AccessControlException();
use Foswiki::Exception ();
use Scalar::Util qw<blessed>;
use Types::Standard qw<InstanceOf Str>;
use Type::Utils -all;

use Foswiki::Class;
extends qw( FoswikiFnTestCase );
Expand Down Expand Up @@ -227,7 +230,8 @@ sub test_ObjectThrowNoText {
$this->assert( blessed($e), "unblessed exception object" );
$this->assert_str_equals( 'Foswiki::Exception::TestException',
ref($e), "incorrect exception class " . ref($e) );
$this->assert_equals( $e->text, "text attribute hasn't been set" );
$this->assert_equals( "exception text attribute hasn't been set",
$e->text );
};
}

Expand Down
Loading

0 comments on commit 74b0b63

Please sign in to comment.