Created
March 3, 2012 16:15
-
-
Save jnthn/1966845 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
[ | |
{ | |
"name": "FlightBookedEvent", | |
"values": [ "flight_code", "passenger_name", "cost" ] | |
}, | |
{ | |
"name": "FlightCancelledEvent", | |
"values": [ "flight_code", "passenger_name" ] | |
} | |
] |
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
module Events; | |
use JSON::Tiny; | |
package EXPORT::DEFAULT { } | |
my @events = @(from-json(slurp("events.json"))); | |
for @events -> (:$name, :@values) { | |
my $type := Metamodel::ClassHOW.new_type(:$name); | |
for @values -> $attr_name { | |
$type.HOW.add_attribute($type, Attribute.new( | |
:name('$!' ~ $attr_name), :type(Mu), | |
:has_accessor(1), :package($type) | |
)); | |
} | |
$type.HOW.compose($type); | |
EXPORT::DEFAULT.WHO{$name} := $type; | |
} |
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
use Events; | |
my $e1 = FlightBookedEvent.new( | |
flight_code => 'AB123', | |
passenger_name => 'jnthn', | |
cost => 100); | |
say $e1.perl; | |
my $e2 = FlightCancelledEvent.new( | |
flight_code => 'AB123', | |
passenger_name => 'jnthn'); | |
say $e2.flight_code; | |
say $e2.passenger_name; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment