evalEmpire / Mite

Mite - A zero dependency, fast loading, Moose-like Perl module
Other
3 stars 1 forks source link

Allow inline data references #5

Open schwern opened 10 years ago

schwern commented 10 years ago

In Moose, if you want a data structure as a default you must use a code ref.

has list =>
    default => sub { [] };

This incurs an object construction penalty for calling that code ref. This is to ensure each object gets its own reference, not the same one over and over again. Because Mite is compiled, we may be able to get around this.

has list =>
    default => [];

Use Data::Dump::Streamer to dump reference defaults (except code refs) and add them to the constructor at compile time.

schwern commented 10 years ago

This can probably get away with just Data::Dumper, data references don't need lexical context, only code references.

Might need a scanner to ensure there's no code refs or filehandles in there.

tobyink commented 2 years ago

I've moved the Mite issue tracker here.

This is now implemented, but only for empty arrayrefs and empty hashrefs, which seem to be the most common use case.