Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, I have to agree with Piers that technically, you really should be calling it as <code>with 'Trello::API::Roles::Authable'</code>. </p> <p>So, you're asking for something that I don't find to be implemented in basic Moose. I have used the ideas of generic namespace pools before. They are sort of universal namespaces to which you can offer your semi-anonymous services--without the lock-in of a fixed namespace. I refined my basic idea of the namespace pool with Moose (really <em><code>MOP</code></em>) support.</p> <p>In the Wild West days of Perl, all you would have to do is assign one stash to the symbol for the other, like so: </p> <pre><code>{ no strict 'refs'; *{$short_pkg_name.'::'} = \*{$full_pkg_name.'::'}; }; </code></pre> <p>And, those two packages were exactly the same things!</p> <p>But now, we guard our data with lexicals a bit more. And because Class::MOP jealously guards its meta objects in a lexical hash, you have to add something else: </p> <pre><code>Class::MOP::store_metaclass_by_name( $short_pkg_name , Class::MOP::get_metaclass_by_name( $full_pkg_name ) ); </code></pre> <p>Now they are the exact same thing to Perl and to MOP. </p> <p>Thus you can create packages that are simply a namespace repository for other packages -- <em>Now with <code>MOP</code> support!</em></p> <pre><code>package Namespace::Pool; use strict; use warnings; use Params::Util qw&lt;_POSINT&gt;; sub import { shift; # It's just me. my $full_pkg_name = caller(); Carp::croak( "'$full_pkg_name' is short enough!" ) unless my $pool_name = shift // [ split /::/, $full_pkg_name ]-&gt;[-2] ; Carp::croak( "'::$pool_name\::' not found in '$full_pkg_name'" ) unless ( _POSINT( my $pos = rindex( $full_pkg_name, "::$pool_name\::" )) or my $is_short = _POSINT( index( $pool_name, '::' )) ); my $short_pkg_name = $is_short ? $poll_name : substr( $full_pkg_name, $pos + 2 ) ; { no strict 'refs'; if ( %{$short_pkg_name.'::'} ) { Carp::croak( "You have already defined $short_pkg_name!" ); } *{$short_pkg_name.'::'} = \*{$full_pkg_name.'::'}; }; if ( my $meta = Class::MOP::get_metaclass_by_name( $full_pkg_name )) { Class::MOP::store_metaclass_by_name( $short_pkg_name, $meta ); } return; } </code></pre> <p>Thus in your Role package you can do the following: </p> <pre><code>package Trello::API::Roles::Authable; use strict; use warnings; use Moose::Role; use Namespace::Pool 'Roles'; ... </code></pre> <p>And know that it will be available from the namespace of 'Roles'.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload