tobyink/p5-type-tiny

Type::Library should defer to the type constraint to figure out what it should export for the type

tobyink opened this issue · 3 comments

There's too much logic in add_type and _exporter_expand_sub.

Instead, Type::Library should call $type->exportables. That should return something like:

[
  { name => "Foo",        tag => "types",     code => sub () { $type } },
  { name => "is_Foo",     tag => "is",        code => sub { ... }      },
  { name => "assert_Foo", tag => "assert",    code => sub { ... }      },
  { name => "to_Foo",     tag => "to",        code => sub { ... }      },
  { name => "FOO_BAR",    tag => "constants", code => sub () { 'bar' } },
  { name => "FOO_BAZ",    tag => "constants", code => sub () { 'baz' } },
]

exportables can probably be a lazy-built attribute rather than a method.

Useful for #114 and to a certain extent #113.

Type::Library::_exporter_expand_tag can probably be completely eliminated.

Type::Library::_mksub can probably be moved to Eval::TypeTiny or somewhere. Same with _subname (and that can probably be shared with Type::Params).

Type::Library::_exporter_permitted_regexp can probably be eliminated.