Perl-Apollo / Corinna

Corinna - Bring Modern OO to the Core of Perl
Artistic License 2.0
157 stars 19 forks source link

Roles which export, default search namespace for roles #22

Closed jbarrett closed 3 years ago

jbarrett commented 3 years ago

Forgive me if this doesn't make sense. What I'm thinking is, roles could perform imports on their consuming class.

The Async role consumed here would create a $loop slot with an instance of your event loop. It would also import keywords from, e.g., Future::AsyncAwait.

# This is just to give you an idea...
class Foo does Async {
    has $http :builder;

    method _build_http() {
        $http = Some::Async::Agent->new();
        $loop->add( $http );
    }

    async method http_get( $url ) {
        await $http->get( $url )
    }
}

The default search namespace would be so package authors could include some Cor::Role::Bar along with their Bar package... class Foo does Bar could go find this role, and it could effect the Class' definition and namespace without an explicit use Bar.

Thanks for reading!

jbarrett commented 3 years ago

I've pinned down my thinking here a little... It goes : "Rails ate Perl's lunch and Node ate Rails' lunch - must make async seamless somehow" ... so here we are with this.

I guess if caller() is consistent during consumption, the role can Import::Into all it likes, but I think I'm looking in the wrong place altogether.

I still think the idea of an author shipping a role may have merit in limited circumstances, but automagically hitting the library path for a bunch of constructed module names probably does not.

(Insert Frank-Drebin-nothing-to-see-here.gif)