Skip to content

Instantly share code, notes, and snippets.

@tony-o
Last active October 18, 2018 17:36
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 tony-o/c7e08d5bed8077616430a55177e5fcf8 to your computer and use it in GitHub Desktop.
Save tony-o/c7e08d5bed8077616430a55177e5fcf8 to your computer and use it in GitHub Desktop.

relevant code:

#composing the types on initialization (from YAML)
$new-model.HOW.add_attribute($new-model, Attribute.new(
  :name<@.columns>, :has_accessor(1), :type(Array), :package($new-model.WHAT),
));

#later in BUILD
multi submethod BUILD (:$!driver, :$!db, :$!quote, :$!dbo, :@columns?) {
  use nqp;
  say self.WHAT.^name; # matches the $new-model name
  "Attributes: {self.^attributes.map({ .gist }).join(", ")}".say;
  nqp::p6bindattrinvres(self, Array, '@!columns', @columns);

output:

Koos::Models::Customer
Attributes: Array @.columns, Mu $!table-name, Mu $!db, Mu $!quote, Mu $!model-class, Mu $!driver, Mu $!row-class, Mu $!dbo, Mu $!filter, Mu $!options, Mu $!inflate, Mu $!first-next
P6opaque: no such attribute '@!columns' on type Array in a Koos::Models::Customer when trying to bind a value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment