From: Shawn M Moore Date: Wed, 28 Jan 2009 07:51:48 +0000 (+0000) Subject: Return list references from words, lines, and split for maximal autobox X-Git-Tag: 0_10~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bf86825986f42b8447522a62c309e06743cac06a;p=gitmo%2FMoose-Autobox.git Return list references from words, lines, and split for maximal autobox goodness --- diff --git a/lib/Moose/Autobox/String.pm b/lib/Moose/Autobox/String.pm index cb3c77a..6da1be9 100644 --- a/lib/Moose/Autobox/String.pm +++ b/lib/Moose/Autobox/String.pm @@ -15,8 +15,8 @@ sub chomp { CORE::chomp $_[0] } sub chop { CORE::chop $_[0] } sub reverse { CORE::reverse $_[0] } sub length { CORE::length $_[0] } -sub lines { CORE::split '\n', $_[0] } -sub words { CORE::split ' ', $_[0] } +sub lines { [ CORE::split '\n', $_[0] ] } +sub words { [ CORE::split ' ', $_[0] ] } sub index { return CORE::index($_[0], $_[1]) if scalar @_ == 2; return CORE::index($_[0], $_[1], $_[2]); @@ -26,8 +26,8 @@ sub rindex { return CORE::rindex($_[0], $_[1], $_[2]); } sub split { - return CORE::split($_[1], $_[0]) if scalar @_ == 2; - return CORE::split($_[1], $_[0], $_[2]); + return [ CORE::split($_[1], $_[0]) ] if scalar @_ == 2; + return [ CORE::split($_[1], $_[0], $_[2]) ]; } 1; diff --git a/t/005_string.t b/t/005_string.t index 0701f2d..e296653 100644 --- a/t/005_string.t +++ b/t/005_string.t @@ -47,9 +47,9 @@ is('Hello World, Hello'->rindex('Hello'), 13, '... got the correct right index') is('Hello World, Hello'->rindex('Hello', 6), 0, '... got the correct right index'); -is_deeply(['/foo/bar/baz'->split('/')], ['', 'foo', 'bar', 'baz'], '... got the correct fragments'); -is_deeply(['Hello World'->words], ['Hello', 'World'], '... got the correct words'); -is_deeply(["Hello\nWor\n\nld\n"->lines], ['Hello', 'Wor', '', 'ld'], '... got the correct lines'); +is_deeply('/foo/bar/baz'->split('/'), ['', 'foo', 'bar', 'baz'], '... got the correct fragments'); +is_deeply('Hello World'->words, ['Hello', 'World'], '... got the correct words'); +is_deeply("Hello\nWor\n\nld\n"->lines, ['Hello', 'Wor', '', 'ld'], '... got the correct lines'); eval 'Hello World, Hello'->dump; is($VAR1, 'Hello World, Hello' , '... eval of &dump works');