Skip to content

Commit

Permalink
Item14237: Complete switch over to use of Type::Tiny.
Browse files Browse the repository at this point in the history
Replaced 'isa' with 'assert' where it makes sense.
  • Loading branch information
vrurg committed May 18, 2018
1 parent 86a91e9 commit f615b55
Show file tree
Hide file tree
Showing 68 changed files with 246 additions and 491 deletions.
8 changes: 3 additions & 5 deletions EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin/Table.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use Foswiki::Plugins::EditRowPlugin::TableRow ();
use Foswiki::Plugins::EditRowPlugin::Editor ();
use Foswiki::Tables::Table ();

use Moo;
use namespace::clean;
use Foswiki::Class -types;
extends qw(Foswiki::Tables::Table);

use constant TRACE => 0;
Expand Down Expand Up @@ -46,9 +45,8 @@ our %editors = ( _default => Foswiki::Plugins::EditRowPlugin::Editor->new() );
has editable => ( is => 'rw', );
has dead_cols => ( is => 'rw', );
has metaObject => (
is => 'rw',
isa =>
Foswiki::Object::isaCLASS( 'metaObject', 'Foswiki::Meta', noUndef => 1 ),
is => 'rw',
assert => InstanceOf ['Foswiki::Meta'],
);

around BUILDARGS => sub {
Expand Down
8 changes: 2 additions & 6 deletions JsonRpcContrib/lib/Foswiki/Contrib/JsonRpcContrib.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package Foswiki::Contrib::JsonRpcContrib;
use Foswiki::Request ();
use Foswiki::Contrib::JsonRpcContrib::Server ();

use Foswiki::Class;
use Foswiki::Class -types;
extends qw(Foswiki::UI);

#BEGIN {
Expand Down Expand Up @@ -35,11 +35,7 @@ has server => (
default => sub {
return $_[0]->create('Foswiki::Contrib::JsonRpcContrib::Server');
},
isa => Foswiki::Object::isaCLASS(
'SERVER',
'Foswiki::Contrib::JsonRpcContrib::Server',
noUndef => 1,
),
assert => InstanceOf ['Foswiki::Contrib::JsonRpcContrib::Server'],
);

sub BUILD {
Expand Down
5 changes: 2 additions & 3 deletions JsonRpcContrib/lib/Foswiki/Contrib/JsonRpcContrib/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# As per the GPL, removal of this notice is prohibited.

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

use JSON ();
use Encode ();
Expand All @@ -25,14 +24,14 @@ use Foswiki::Func ();
use Foswiki::Plugins ();
use constant TRACE => 0; # toggle me

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

has data => (
is => 'rw',
lazy => 1,
default => sub { {} },
isa => Foswiki::Object::isaHASH( 'data', noUndef => 1, ),
assert => HashRef,
);
has namespace => ( is => 'rw', );
has json => (
Expand Down
8 changes: 2 additions & 6 deletions JsonRpcContrib/lib/Foswiki/Contrib/JsonRpcContrib/Response.pm
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 -app;
use Foswiki::Class -app, -types;
extends qw(Foswiki::Object);

use constant TRACE => 0; # toggle me
Expand All @@ -33,11 +33,7 @@ has code => (
is => 'rw',
lazy => 1,
default => 0,
isa => sub {
Foswiki::Exception::Fatal->throw(
text => __PACKAGE__ . "::code object attribute cannot be undef" )
unless defined $_[0];
},
isa => Value,
);
has json => (
is => 'ro',
Expand Down
19 changes: 8 additions & 11 deletions JsonRpcContrib/lib/Foswiki/Request/JSON.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ The following fields are parsed from the path_info and/or query params
=cut

package Foswiki::Request::JSON;
use v5.14;

use Assert;
use Try::Tiny;
Expand All @@ -26,21 +25,21 @@ use Foswiki::Func ();
use Foswiki::Plugins ();
use CGI::Util qw(rearrange);

use Moo;
use namespace::clean;
use Foswiki::Class -types;
extends qw(Foswiki::Request);

=begin TML
---++ ObjectAttribute json -> $JSON object
Returns the JSON object, or a new JSON object if wne has not already been created.
Returns the JSON object, or a new JSON object if one has not already been
created.
=cut

has json => (
is => 'rw',
lazy => 1,
isa => Foswiki::Object::isaCLASS( 'json', 'JSON' ),
is => 'rw',
lazy => 1,
assert => Maybe [ InstanceOf ['JSON'] ],
default => sub { return JSON->new },
);

Expand Down Expand Up @@ -77,15 +76,13 @@ are reported later.
has jsonerror => (
is => 'rw',
predicate => 1,
isa => Foswiki::Object::isaCLASS(
'jsonerror', 'Foswiki::Contrib::JsonRpcContrib::Error'
),
assert => Maybe [ InstanceOf ['Foswiki::Contrib::JsonRpcContrib::Error'] ],
);
has jsondata => (
is => 'rw',
lazy => 1,
predicate => 1,
isa => Foswiki::Object::isaHASH( 'jsondata', noUndef => 1, ),
assert => HashRef,
clearer => 1,
builder => '_establishJSON',
);
Expand Down
7 changes: 4 additions & 3 deletions UnitTestContrib/lib/Unit/FoswikiTestRole.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use Foswiki::Exception;
# Use variable to let it be easily incorporated into a regex.
our $TEST_WEB_PREFIX = 'Temporary';

use Moo::Role;
use Foswiki::Role -types;
roleInit;

our @mails;

Expand All @@ -36,8 +37,8 @@ has app => (
lazy => 1,
predicate => 1,
clearer => 1,
isa => Foswiki::Object::isaCLASS( 'app', 'Unit::TestApp', noUndef => 1, ),
default => sub {
isa => InstanceOf ['Unit::TestApp'],
default => sub {
return Unit::TestApp->new( env => { map { $_ => $ENV{$_} } keys %ENV },
);
},
Expand Down
4 changes: 2 additions & 2 deletions UnitTestContrib/lib/Unit/PlackTestCase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ use Try::Tiny;
use HTML::Parser;
require Unit::TestRunner;

use Foswiki::Class;
use Foswiki::Class -types;
extends qw(Unit::TestCase);
with qw(Foswiki::Util::Localize Unit::FoswikiTestRole);

Expand Down Expand Up @@ -334,7 +334,7 @@ around prepareTestClientList => sub {
has testClientList => (
is => 'rw',
lazy => 1,
isa => Foswiki::Object::isaARRAY( 'testList', noUndef => 1, ),
isa => ArrayRef [HashRef],
builder => 'prepareTestClientList',
);

Expand Down
4 changes: 2 additions & 2 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 -callbacks;
use Foswiki::Class -callbacks, -types;
extends qw(Foswiki::App);

=begin TML
Expand Down Expand Up @@ -108,7 +108,7 @@ has callbacks => (
is => 'rw',
lazy => 1,
predicate => 1,
isa => Foswiki::Object::isaHASH('callbacks'),
isa => HashRef,
default => sub { {} },
);

Expand Down
4 changes: 2 additions & 2 deletions UnitTestContrib/test/unit/FoswikiFnTestCase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use Foswiki::UI::Register();
use Try::Tiny;
use Carp qw(cluck);

use Foswiki::Class;
use Foswiki::Class -types;
extends qw(FoswikiTestCase);

has test_user_forename => ( is => 'rw', );
Expand All @@ -45,7 +45,7 @@ has response => (
clearer => 1,
lazy => 1,
predicate => 1,
isa => Foswiki::Object::isaCLASS( 'response', 'Foswiki::Response' ),
isa => InstanceOf ['Foswiki::Response'],
default => sub { return $_[0]->app->response; },
);

Expand Down
7 changes: 3 additions & 4 deletions UnitTestContrib/test/unit/FoswikiTestCase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ my $cleanup = $ENV{FOSWIKI_DEBUG_KEEP} ? 0 : 1;

our $didOnlyOnceChecks = 0;

use Foswiki::Class;
use Foswiki::Class -types;
extends qw(Unit::TestCase);
with qw(Foswiki::Util::Localize Unit::FoswikiTestRole);

Expand All @@ -54,7 +54,7 @@ has test_topicObject => (
is => 'rw',
clearer => 1,
predicate => 1,
isa => Foswiki::Object::isaCLASS( 'test_topicObject', 'Foswiki::Meta' ),
isa => Maybe [ InstanceOf ['Foswiki::Meta'] ],

# For compatibility with Foswiki::Func::readTopic we accept arrayref and
# fetch it's first element if it is a Foswiki::Meta object but only if it
Expand All @@ -76,8 +76,7 @@ has request => (
$_[0]->app->request;
},
clearer => 1,
isa =>
Foswiki::Object::isaCLASS( 'request', 'Foswiki::Request', noUndef => 1, ),
isa => InstanceOf ['Foswiki::Request'],
);

BEGIN {
Expand Down
6 changes: 2 additions & 4 deletions UnitTestContrib/test/unit/HTMLValidationTests.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package HTMLValidationTests;
use v5.14;

#this has been quickly copied from the UICompilation tests
#TODO: need to pick a list of topics, actions, opps's and add detection of installed skins
Expand All @@ -10,8 +9,7 @@ use Foswiki::UI::View();
use HTML::Tidy();
use Try::Tiny;

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

has script_name => ( is => 'rw' );
Expand All @@ -20,7 +18,7 @@ has skin_name => ( is => 'rw' );

has tidy => (
is => 'rw',
isa => Foswiki::Object::isaCLASS( 'tidy', 'HTML::Tidy', noUndef => 1 ),
isa => InstanceOf ['HTML::Tidy'],
lazy => 1,
default => sub {

Expand Down
6 changes: 2 additions & 4 deletions UnitTestContrib/test/unit/HoistREsTests.pm
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# Test for hoisting REs from query expressions
package HoistREsTests;
use v5.14;

use Foswiki::Query::Parser;
use Foswiki::Query::HoistREs;
use Foswiki::Query::Node;

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

has meta => (
is => 'rw',
isa => Foswiki::Object::isaCLASS( 'meta', 'Foswiki::Meta', noUndef => 1 ),
isa => InstanceOf ['Foswiki::Meta'],
);

sub skip {
Expand Down
6 changes: 2 additions & 4 deletions UnitTestContrib/test/unit/QueryTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
# query syntax.

package QueryTests;
use v5.14;

use Foswiki::Query::Parser;
use Foswiki::Query::Node;
use Foswiki::Func();

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

use constant MONITOR => 0;
Expand All @@ -27,7 +25,7 @@ my %qalgs;

has metaObject => (
is => 'rw',
isa => Foswiki::Object::isaCLASS( 'metaObject', 'Foswiki::Meta' ),
isa => InstanceOf ['Foswiki::Meta'],
);

around BUILDARGS => sub {
Expand Down
6 changes: 2 additions & 4 deletions UnitTestContrib/test/unit/StoreImplementationTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@
# No method of Foswiki::Func should be called
#
package StoreImplementationTests;
use v5.14;

use Assert;
use Foswiki ();
use Foswiki::Meta ();
use Try::Tiny;

use Moo;
use namespace::clean;
use Foswiki::Class -types;
extends qw( FoswikiStoreTestCase );

has sut => (
is => 'rw',
isa => Foswiki::Object::isaCLASS( 'sut', 'Foswiki::Store', noUndef => 1, ),
isa => InstanceOf ['Foswiki::Store'],
);

sub skip {
Expand Down
1 change: 1 addition & 0 deletions UnitTestContrib/test/unit/TypesTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ sub test_AllOf {
package __FCT::TstRole;
use Foswiki::Role;
roleInit;
TSTROLE

Expand Down
11 changes: 3 additions & 8 deletions core/lib/Foswiki/Address.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use Assert;
use Foswiki::Func();
use Foswiki::Meta();

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

#use Data::Dumper;
Expand Down Expand Up @@ -194,20 +194,15 @@ has _web => ( is => 'rw', init_args => 'web', );
has webpath => (
is => 'rw',
trigger => sub { $_[0]->_invalidate; },
isa => Foswiki::Object::isaARRAY( __PACKAGE__ . "::webpath" ),
assert => Maybe [ArrayRef],
);
has topic => (
is => 'rw',
trigger => \&_validationTrigger,
);
has _rev => ( is => 'rw', init_arg => 'rev', );
has tompath => (
is => 'rw',

# SMELL It seems that Moo has a bug with execution order when both isa and
# trigger are defined. In this case trigger is called before new value is
# assigned to the attribute.
#isa => Foswiki::Object::isaARRAY( __PACKAGE__ . "::tompath", noEmpty => 1 ),
is => 'rw',
trigger => sub { $_[0]->_validationTrigger; },
);
has attachment => (
Expand Down
Loading

0 comments on commit f615b55

Please sign in to comment.