Guest User

Untitled

a guest
Jan 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use Test::More;
  5. use Test::Fatal;
  6.  
  7. {
  8. package Foo;
  9. use Moose;
  10.  
  11. has bar => (
  12. is => 'rw',
  13. isa => 'Bar',
  14. );
  15. }
  16.  
  17. {
  18. package Bar;
  19. use Moose;
  20.  
  21. has foo => (
  22. is => 'rw',
  23. isa => 'Foo',
  24. weak_ref => 1,
  25. );
  26. }
  27.  
  28. {
  29. package MyApp;
  30. use Moose;
  31. use Bread::Board::Declare;
  32.  
  33. has foo => (
  34. is => 'ro',
  35. isa => 'Foo',
  36. block => sub {
  37. my ($s, $self) = @_;
  38.  
  39. my $foo = Foo->new(bar => $s->param('bar'));
  40. return $foo;
  41. },
  42. lifecycle => 'Singleton',
  43. dependencies => ['bar'],
  44. );
  45. has bar => (
  46. is => 'ro',
  47. isa => 'Bar',
  48. block => sub {
  49. my ($s, $self) = @_;
  50. my $bar = Bar->new(foo => $s->param('foo'));
  51. },
  52. lifecycle => 'Singleton',
  53. dependencies => ['foo'],
  54. );
  55. }
  56.  
  57.  
  58. is exception { MyApp->new->foo->bar }, undef,
  59. 'circular block-injection deps should survive';
  60.  
  61. done_testing();
Add Comment
Please, Sign In to add comment