issue301.t 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #! /usr/bin/env perl
  2. # http://code.google.com/p/perl-compiler/issues/detail?id=301
  3. # detect (maybe|next)::(method|can) mro method calls
  4. # also check #326 maybe::next::method()
  5. use strict;
  6. BEGIN {
  7. unshift @INC, 't';
  8. require "test.pl";
  9. }
  10. use Test::More;
  11. plan ($] > 5.007003 ? (tests => 2) : (skip_all => "no NEXT on $]"));
  12. my $script = <<EOF;
  13. use mro;
  14. {
  15. package A;
  16. sub foo { 'A::foo' }
  17. }
  18. {
  19. package C;
  20. use base 'A';
  21. sub foo { (shift)->next::method() }
  22. }
  23. print qq{ok} if C->foo eq 'A::foo'
  24. EOF
  25. if ($] < 5.010) {
  26. $script =~ s/mro/NEXT/m;
  27. $script =~ s/next::/NEXT::/m;
  28. $script =~ s/method/foo/m;
  29. }
  30. # mro since 5.10 only
  31. ctestok(1, 'C,-O3', 'ccode301i', $script, '#301 next::method detection');
  32. $script = <<EOF;
  33. package Diamond_C;
  34. sub maybe { "Diamond_C::maybe" }
  35. package Diamond_D;
  36. use base "Diamond_C";
  37. use mro "c3";
  38. sub maybe { "Diamond_D::maybe => " . ((shift)->maybe::next::method() || 0) }
  39. package main; print "ok\n" if Diamond_D->maybe;
  40. EOF
  41. if ($] < 5.010) {
  42. $script =~ s/mro/NEXT/m;
  43. $script =~ s/maybe::next::/NEXT::DISTINCT::/m;
  44. $script =~ s/::method/::maybe/m;
  45. }
  46. ctestok(2, 'C,-O3', 'ccode326i', $script, '#326 maybe::next::method detection');