From: Vincent Pit Date: Tue, 20 Aug 2013 19:32:07 +0000 (-0300) Subject: Get rid of the indirect notation X-Git-Tag: v0.07~2 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=72cae6c1d4dcdbfe9b437dc8a8949ce282bffeb0;p=perl%2Fmodules%2FBit-MorseSignals.git Get rid of the indirect notation --- diff --git a/lib/Bit/MorseSignals.pm b/lib/Bit/MorseSignals.pm index 8e1a892..cab439f 100644 --- a/lib/Bit/MorseSignals.pm +++ b/lib/Bit/MorseSignals.pm @@ -20,8 +20,8 @@ our $VERSION = '0.06'; use Bit::MorseSignals::Emitter; use Bit::MorseSignals::Receiver; - my $deuce = new Bit::MorseSignals::Emitter; - my $pants = new Bit::MorseSignals::Receiver done => sub { print $_[1], "\n" }; + my $deuce = Bit::MorseSignals::Emitter->new; + my $pants = Bit::MorseSignals::Receiver->new(done => sub { print $_[1], "\n" }); $deuce->post('HLAGH') for 1 .. 3; $pants->push while defined ($_ = $deuce->pop); diff --git a/lib/Bit/MorseSignals/Emitter.pm b/lib/Bit/MorseSignals/Emitter.pm index af654a2..54203af 100644 --- a/lib/Bit/MorseSignals/Emitter.pm +++ b/lib/Bit/MorseSignals/Emitter.pm @@ -25,7 +25,7 @@ our $VERSION = '0.06'; use Bit::MorseSignals::Emitter; - my $deuce = new Bit::MorseSignals::Emitter; + my $deuce = Bit::MorseSignals::Emitter->new; $deuce->post("hlagh") for 1 .. 3; while (defined(my $bit = $deuce->pop)) { sends_by_some_mean_lets_say_signals($bit); diff --git a/lib/Bit/MorseSignals/Receiver.pm b/lib/Bit/MorseSignals/Receiver.pm index c21c44e..874bb9a 100644 --- a/lib/Bit/MorseSignals/Receiver.pm +++ b/lib/Bit/MorseSignals/Receiver.pm @@ -25,7 +25,7 @@ our $VERSION = '0.06'; use Bit::MorseSignals::Receiver; - my $pants = new Bit::MorseSignals::Receiver done => sub { print "received $_[1]!\n" }; + my $pants = Bit::MorseSignals::Receiver->new(done => sub { print "received $_[1]!\n" }); while (...) { my $bit = comes_from_somewhere_lets_say_signals(); $pants->push($bit); diff --git a/t/20-emitter-obj.t b/t/20-emitter-obj.t index 1c25382..9232265 100644 --- a/t/20-emitter-obj.t +++ b/t/20-emitter-obj.t @@ -7,7 +7,7 @@ use Test::More tests => 25; use Bit::MorseSignals::Emitter; -my $deuce = new Bit::MorseSignals::Emitter; +my $deuce = Bit::MorseSignals::Emitter->new; ok(defined $deuce, 'BME object is defined'); is(ref $deuce, 'Bit::MorseSignals::Emitter', 'BME object is valid'); @@ -16,7 +16,7 @@ ok(defined $deuce2, 'BME::new called as an object method works' ); is(ref $deuce2, 'Bit::MorseSignals::Emitter', 'BME::new called as an object method works is valid'); ok(!defined Bit::MorseSignals::Emitter::new(), 'BME::new called without a class is invalid'); -eval { $deuce2 = new Bit::MorseSignals::Emitter qw/a b c/ }; +eval { $deuce2 = Bit::MorseSignals::Emitter->new(qw/a b c/) }; like($@, qr/Optional\s+arguments/, 'BME::new gets parameters as key => value pairs'); my $fake = { }; diff --git a/t/21-emitter-plain.t b/t/21-emitter-plain.t index 812389a..378e494 100644 --- a/t/21-emitter-plain.t +++ b/t/21-emitter-plain.t @@ -7,7 +7,7 @@ use Test::More 'no_plan'; use Bit::MorseSignals::Emitter; -my $deuce = new Bit::MorseSignals::Emitter; +my $deuce = Bit::MorseSignals::Emitter->new; sub test_msg { my ($desc, $exp, $try_post) = @_; diff --git a/t/22-emitter-utf8.t b/t/22-emitter-utf8.t index 575c66a..9647ecf 100644 --- a/t/22-emitter-utf8.t +++ b/t/22-emitter-utf8.t @@ -10,7 +10,7 @@ use Test::More 'no_plan'; use Bit::MorseSignals qw/BM_DATA_PLAIN/; use Bit::MorseSignals::Emitter; -my $deuce = new Bit::MorseSignals::Emitter utf8 => 'DO WANT'; +my $deuce = Bit::MorseSignals::Emitter->new(utf8 => 'DO WANT'); sub test_msg { my ($desc, $exp) = @_; diff --git a/t/30-receiver-obj.t b/t/30-receiver-obj.t index 53f8d44..79b5615 100644 --- a/t/30-receiver-obj.t +++ b/t/30-receiver-obj.t @@ -7,7 +7,7 @@ use Test::More tests => 15; use Bit::MorseSignals::Receiver; -my $pants = new Bit::MorseSignals::Receiver; +my $pants = Bit::MorseSignals::Receiver->new; ok(defined $pants, 'BMR object is defined'); is(ref $pants, 'Bit::MorseSignals::Receiver', 'BMR object is valid'); @@ -16,7 +16,7 @@ ok(defined $pants2, 'BMR::new called as an object method works' ); is(ref $pants2, 'Bit::MorseSignals::Receiver', 'BMR::new called as an object method works is valid'); ok(!defined Bit::MorseSignals::Receiver::new(), 'BMR::new called without a class is invalid'); -eval { $pants2 = new Bit::MorseSignals::Receiver qw/a b c/ }; +eval { $pants2 = Bit::MorseSignals::Receiver->new(qw/a b c/) }; like($@, qr/Optional\s+arguments/, 'BME::new gets parameters as key => value pairs'); my $fake = { }; diff --git a/t/31-receiver-plain.t b/t/31-receiver-plain.t index 899f3f2..2798095 100644 --- a/t/31-receiver-plain.t +++ b/t/31-receiver-plain.t @@ -9,7 +9,7 @@ use Bit::MorseSignals::Receiver; my $hlagh; -my $pants = new Bit::MorseSignals::Receiver done => sub { $hlagh = $_[1] }; +my $pants = Bit::MorseSignals::Receiver->new(done => sub { $hlagh = $_[1] }); my $msg = 'x'; my @bits = split //, '111110' . '000' . '00011110' . '011111'; diff --git a/t/32-receiver-utf8.t b/t/32-receiver-utf8.t index f11a431..f42657d 100644 --- a/t/32-receiver-utf8.t +++ b/t/32-receiver-utf8.t @@ -9,7 +9,7 @@ use Test::More tests => 1; use Bit::MorseSignals::Receiver; -my $pants = new Bit::MorseSignals::Receiver; +my $pants = Bit::MorseSignals::Receiver->new; my $msg = 'é'; my @bits = split //, '11110' . '100' . '11000011' . '10010101' . '01111'; diff --git a/t/33-receiver-misformed.t b/t/33-receiver-misformed.t index 9fde631..fc7a819 100644 --- a/t/33-receiver-misformed.t +++ b/t/33-receiver-misformed.t @@ -11,7 +11,7 @@ use Bit::MorseSignals::Receiver; my $hlagh; -my $pants = new Bit::MorseSignals::Receiver done => sub { $hlagh = $_[1] }; +my $pants = Bit::MorseSignals::Receiver->new(done => sub { $hlagh = $_[1] }); my $wrong = "\x{FF}\x{FF}"; diff --git a/t/50-chitchat-plain.t b/t/50-chitchat-plain.t index 18750b1..b1bafc5 100644 --- a/t/50-chitchat-plain.t +++ b/t/50-chitchat-plain.t @@ -11,11 +11,11 @@ use Bit::MorseSignals::Receiver; my @msgs = qw/hlagh hlaghlaghlagh HLAGH HLAGHLAGHLAGH \x{0dd0}\x{00} h\x{00}la\x{00}gh \x{00}\x{ff}\x{ff}\x{00}\x{00}\x{ff}/; -my $deuce = new Bit::MorseSignals::Emitter; -my $pants = new Bit::MorseSignals::Receiver done => sub { +my $deuce = Bit::MorseSignals::Emitter->new; +my $pants = Bit::MorseSignals::Receiver->new(done => sub { my $cur = shift @msgs; is($_[1], $cur, 'received message is correct'); -}; +}); $deuce->post($_) for @msgs; $pants->push while defined ($_ = $deuce->pop); # ))<>(( diff --git a/t/51-chitchat-utf8.t b/t/51-chitchat-utf8.t index f224a5e..3d72d97 100644 --- a/t/51-chitchat-utf8.t +++ b/t/51-chitchat-utf8.t @@ -14,11 +14,11 @@ my @msgs = qw/€éèë 月語 x tata たTÂ/; sub cp { join '.', map ord, split //, $_[0] } -my $deuce = new Bit::MorseSignals::Emitter; -my $pants = new Bit::MorseSignals::Receiver done => sub { +my $deuce = Bit::MorseSignals::Emitter->new; +my $pants = Bit::MorseSignals::Receiver->new(done => sub { my $cur = shift @msgs; ok($_[1] eq $cur, 'got ' . cp($_[1]) . ', expected ' . cp($cur)); -}; +}); $deuce->post($_) for @msgs; $pants->push while defined ($_ = $deuce->pop); # ))<>(( diff --git a/t/52-chitchat-storable.t b/t/52-chitchat-storable.t index 7511dae..5a2547c 100644 --- a/t/52-chitchat-storable.t +++ b/t/52-chitchat-storable.t @@ -19,11 +19,11 @@ my @msgs = ( $msgs[7]->{wut} = { dong => [ 0 .. 99 ], recurse => $msgs[7] }; my $i = 0; -my $deuce = new Bit::MorseSignals::Emitter; -my $pants = new Bit::MorseSignals::Receiver done => sub { +my $deuce = Bit::MorseSignals::Emitter->new; +my $pants = Bit::MorseSignals::Receiver->new(done => sub { my $cur = shift @msgs; is_deeply($_[1], $cur, 'got object ' . $i++); -}; +}); $deuce->post($_) for @msgs; $pants->push while defined ($_ = $deuce->pop); # ))<>((