with 'Moose::Autobox::String',
'Moose::Autobox::Number';
-
+
+sub flatten { $_[0] }
sub print { CORE::print $_[0] }
sub say { CORE::print $_[0], "\n" }
1;
=item B<say>
+=item B<flatten>
+
+Flattening a scalar just returns the scalar. This means that you can say:
+
+ my @array = $input->flatten;
+
+ # Given $input of 5, @array is (5);
+ # Given $input of [ 5, 2, 0], @array is (5, 2, 0)
+
=back
=head1 BUGS
use strict;
use warnings;
-use Test::More tests => 69;
+use Test::More tests => 70;
BEGIN {
use_ok('Moose::Autobox');
eval $s->dump;
is($VAR1, 5 , '... eval of SCALAR->dump works');
+eval $s->flatten;
+is($VAR1, 5 , '... eval of SCALAR->flatten works');
+
eval $s->perl;
is($s->perl, $s->dump, '... SCALAR->dump equals SCALAR->perl');
use strict;
use warnings;
-use Test::More tests => 2;
+use Test::More tests => 4;
use Moose::Autobox;
my $array = [ qw(1 2 3 4 ) ];
[ qw(1 2 a b) ],
"flattening a hash returns a list",
);
+
+my $scalar = 1;
+is_deeply(
+ [ $scalar->flatten ],
+ [ 1 ],
+ "flattening a scalar returns the scalar",
+);
+
+my $scalar_ref = \$scalar;
+is_deeply(
+ [ $scalar_ref->flatten ],
+ [ \$scalar ],
+ "flattening a reference to a scalar returns the same scalar reference",
+);