comparison _test/temp.pl @ 412:30e8c6a74937 ref20150831

working on di container (role based registrations)
author cin
date Mon, 21 Sep 2015 19:54:10 +0300
parents ee36115f6a34
children ec6f2d389d1e
comparison
equal deleted inserted replaced
411:ee36115f6a34 412:30e8c6a74937
1 #!/usr/bin/perl 1 #!/usr/bin/perl
2 use strict; 2 use strict;
3 use Carp;
4 use Time::HiRes qw(gettimeofday tv_interval);
5 use Scalar::Util qw(blessed);
6 my $slot;
7 my $ref = bless \$slot, 'Wrapper';
8 sub is {
9 my $slot = shift;
10 bless \$slot, 'Wrapper';
11 }
3 12
4 use IMPL::require { ServicesBag => 'IMPL::Config::ServicesBag' }; 13 sub instanceOf {
14 carp "A typename can't be undefined" unless $_[1];
15 blessed($_[0]) and $_[0]->isa($_[1])
16 }
5 17
6 my $root = ServicesBag->new(); 18 my $bar = Bar->new();
19
20 my $t = [gettimeofday];
21
22 for(my $i =0; $i< 1000000; $i++) {
23 is($bar)->instanceOf('Bar');
24 }
25
26 print "Is: ",tv_interval($t,[gettimeofday]),"\n";
27
28 $t = [gettimeofday];
29
30 for(my $i =0; $i< 1000000; $i++) {
31 instanceOf($bar, 'Bar');
32 }
33
34 print "Is: ",tv_interval($t,[gettimeofday]),"\n";
7 35
8 36
37 package Wrapper;
38 use Scalar::Util qw(blessed);
39 sub instanceOf {
40 blessed(${$_[0]}) and ${$_[0]}->isa($_[1]);
41 }
42
43 package Bar;
44 use IMPL::declare {
45 base => ['IMPL::Object' => undef]
46 };
47
9 1; 48 1;