PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Class-InsideOut-1.10/t/12_storable_hooks.t

#
Unknown | 74 lines | 62 code | 12 blank | 0 comment | 0 complexity | ef5e35637564b54fa75756f4a9d31e13 MD5 | raw file
Possible License(s): Apache-2.0
  1. use strict;
  2. use Test::More;
  3. use Class::InsideOut ();
  4. use Scalar::Util qw( refaddr reftype );
  5. $|++; # keep stdout and stderr in order on Win32
  6. my $class = "t::Object::Animal::Jackalope";
  7. my $gp_class = "t::Object::Animal";
  8. # Need Storable 2.04 ( relatively safe STORABLE_freeze support )
  9. eval { require Storable and Storable->VERSION( 2.04 ) };
  10. if ( $@ ) {
  11. plan skip_all => "Storable >= 2.04 not installed",
  12. }
  13. else
  14. {
  15. plan tests => 10;
  16. }
  17. #--------------------------------------------------------------------------#
  18. # tests
  19. #--------------------------------------------------------------------------#
  20. require_ok( $class );
  21. my $o;
  22. # create the object
  23. ok( $o = $class->new(),
  24. "... Creating $class object"
  25. );
  26. # note the underlying type
  27. my $type;
  28. ok( $type = reftype($o),
  29. "... Object is reftype $type"
  30. );
  31. # freeze object
  32. my ( $frozen, $thawed );
  33. ok( $frozen = Storable::freeze( $o ),
  34. "... Freezing object"
  35. );
  36. # check that hooks worked
  37. {
  38. no strict 'refs';
  39. is( ${ $class . "::freezings"}, 1,
  40. "... $class freeze hook updated freeze count"
  41. );
  42. is( ${ $gp_class . "::freezings"}, 1,
  43. "... $gp_class freeze hook updated freeze count (diamond pattern)"
  44. );
  45. }
  46. # thaw object
  47. ok( $thawed = Storable::thaw( $frozen ),
  48. "... Thawing object"
  49. );
  50. isnt( refaddr $o, refaddr $thawed,
  51. "... Thawed object is a copy"
  52. );
  53. # check that hooks worked
  54. {
  55. no strict 'refs';
  56. is( ${ $class . "::thawings"}, 1,
  57. "... $class thaw hook updated thaw count"
  58. );
  59. is( ${ $gp_class . "::thawings"}, 1,
  60. "... $gp_class thaw hook updated thaw count (diamond pattern)"
  61. );
  62. }