Skip to content

Commit

Permalink
Change boolean value of collection
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusramberg committed May 25, 2014
1 parent c9b5474 commit a8153a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Mojo/Collection.pm
@@ -1,6 +1,9 @@
package Mojo::Collection;
use Mojo::Base -strict;
use overload bool => sub {1}, '""' => sub { shift->join("\n") }, fallback => 1;
use overload
bool => sub { scalar @{shift()} },
'""' => sub { shift->join("\n") },
fallback => 1;

use Carp 'croak';
use Exporter 'import';
Expand Down
5 changes: 5 additions & 0 deletions t/mojo/collection.t
Expand Up @@ -166,4 +166,9 @@ eval { Mojo::Collection::missing() };
like $@, qr/^Undefined subroutine &Mojo::Collection::missing called/,
'right error';

$collection = Mojo::Collection->new();
ok !$collection, 'Empty collection is falsy';
$collection = Mojo::Collection->new('wat');
ok $collection, ' Non-empty collection is truthy ';

done_testing();

0 comments on commit a8153a5

Please sign in to comment.