Created
August 19, 2014 11:34
-
-
Save libitte/745df3c4ff0605f92585 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use Data::Dumper; | |
| package A; | |
| sub new { | |
| my ($class, $user_id) = @_; | |
| bless {user_id => $user_id}, $class; | |
| } | |
| package B; | |
| sub new { | |
| my ($class, $people) = @_; | |
| bless {people => $people}, $class; | |
| } | |
| package C; | |
| sub new { | |
| my ($class, $foo) = @_; | |
| bless {foo => $foo}, $class; | |
| } | |
| package main; | |
| sub die_test { | |
| my ($class) = @_; | |
| my $a = A->new(1_000); | |
| my $b = B->new([1_000, 2_000]); | |
| my $c = C->new('foobar2000'); | |
| eval { | |
| die $a if $class eq 'A'; | |
| die $b if $class eq 'B'; | |
| die $c if $class eq 'C'; | |
| }; | |
| if (ref($@) eq 'A') { | |
| print "class A\n" . Dumper $@; | |
| } | |
| if (ref($@) eq 'B') { | |
| print "class B\n" . Dumper $@; | |
| } | |
| if (ref($@) eq 'C') { | |
| print "class C\n" . Dumper $@; | |
| } | |
| } | |
| main::die_test('A'); | |
| main::die_test('B'); | |
| main::die_test('C'); | |
| __END__ | |
| class A | |
| $VAR1 = bless( { | |
| 'user_id' => 1000 | |
| }, 'A' ); | |
| class B | |
| $VAR1 = bless( { | |
| 'people' => [ | |
| 1000, | |
| 2000 | |
| ] | |
| }, 'B' ); | |
| class C | |
| $VAR1 = bless( { | |
| 'foo' => 'foobar2000' | |
| }, 'C' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment