tobyink / p5-type-tiny

Perl 5 distribution Type-Tiny; see homepage for downloads and documentation.
https://typetiny.toby.ink/
54 stars 48 forks source link

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

Closed tobyink closed 2 years ago

tobyink commented 2 years ago

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.

tobyink commented 2 years ago

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

tobyink commented 2 years ago

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

tobyink commented 2 years ago

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