Skip to content

Instantly share code, notes, and snippets.

@ashgti
Created May 6, 2010 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashgti/392673 to your computer and use it in GitHub Desktop.
Save ashgti/392673 to your computer and use it in GitHub Desktop.
role Bar {
COMPOSE {
print "Bar() was composed into: ";
print $_; # => What your being composed into
print " and {$_} was defined: ";
say $_.defined; # How to tell if its a class instance or an object instance
}
}
class Foo does Bar {
INHERIT {
print "Foo() was inherited into child: ";
print $_; # => What your being inherited into
}
}
class Child is Foo {
}
class GrandChild is Child {
}
my $i = 123;
$i does Bar;
=begin pod
expected output:
Bar() was composed into: Foo() and Foo() was defined: 0
Foo() was inherited into child: Child()
Foo() was inherited into child: GrandChild()
Bar() was composed into: 123 and 123 was defined: 1
=end pod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment