Skip to content

Commit

Permalink
Item14237: Merge commit 'e284891ddf76d6fc12826097d56532858077d22d' in…
Browse files Browse the repository at this point in the history
…to Item14237

* commit 'e284891ddf76d6fc12826097d56532858077d22d':
  Item13897: Overloading of stringification operator by Foswiki::Object.
  Item13897: Completing the previous commit
  • Loading branch information
vrurg committed Nov 30, 2016
2 parents 4ad7e49 + e284891 commit ceff4cf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
19 changes: 15 additions & 4 deletions UnitTestContrib/lib/Unit/TestApp.pm
Expand Up @@ -79,11 +79,19 @@ has engineParams => (
default => sub { {} },
);

# cfgParams hash is used to initialize a new cfg object.
=begin TML
---++ ObjectAttribute cfgParams -> hash
This is a hash of parameters to be passed over to =Foswiki::Config=
constructor.
=cut

has cfgParams => (
is => 'rw',
lazy => 1,
default => sub { {} },
builder => 'prepareCfgParams',
);

=begin TML
Expand Down Expand Up @@ -196,8 +204,7 @@ around _prepareConfig => sub {
my $orig = shift;
my $this = shift;

my $cfg = $this->create( 'Foswiki::Config', %{ $this->cfgParams } );
return $cfg;
return $this->create( 'Foswiki::Config', %{ $this->cfgParams }, );
};

around handleRequest => sub {
Expand All @@ -219,6 +226,10 @@ around handleRequest => sub {
return $rc;
};

sub prepareCfgParams {
return {};
}

=begin TML
---++ Examples
Expand Down
6 changes: 3 additions & 3 deletions core/lib/Foswiki/Exception.pm
Expand Up @@ -57,7 +57,7 @@ use Foswiki::Class;
extends qw(Foswiki::Object);
with 'Throwable';

use overload '""' => 'to_str';
#use overload '""' => 'to_str';

our $EXCEPTION_TRACE = 0;

Expand Down Expand Up @@ -185,15 +185,15 @@ sub stringify {
);
}

sub to_str {
around to_str => sub {
my $this = shift;

my $boundary = '-' x 60;
my $msg = join( "\n",
$boundary, map( { " " . $_ } split /\n/, $this->stringify ),
$boundary );
return $msg;
}
};

# We must not get into this. But if we do then let's not hide a error but let it
# thru to the end user via JsonRPC interfaces.
Expand Down
19 changes: 19 additions & 0 deletions core/lib/Foswiki/Object.pm
Expand Up @@ -26,6 +26,8 @@ use Scalar::Util qw(blessed refaddr weaken isweak);

use Foswiki::Class;

use overload fallback => 1, '""' => 'to_str';

use Assert;

=begin TML
Expand Down Expand Up @@ -363,6 +365,23 @@ sub clone {
return $newObj;
}

=begin TML
---++ ObjectMethod to_str => $string
This method is used to overload stringification operator "" (see
[[CPAN:overload][=perldoc overload=]]).
The default is to return object itself in order to preserve system default
behavior.
=cut

sub to_str {
my @c = caller;
return $_[0];
}

# Fixes __orig_file and __orig_line to bypass ::create() and point directly to
# where it was called.
# $level parameter – how many stack frames to skip.
Expand Down

0 comments on commit ceff4cf

Please sign in to comment.