OpusVL-AppKit

 view release on metacpan or  search on metacpan

lib/OpusVL/AppKit/Plugin/AppKit.pm  view on Meta::CPAN

package OpusVL::AppKit::Plugin::AppKit;


###########################################################################################################################
# use lines.
###########################################################################################################################
use Moose;
use namespace::autoclean;
use 5.010;
use Tree::Simple;
use Tree::Simple::Visitor::FindByPath;
use OpusVL::AppKit::Plugin::AppKit::Node;
use OpusVL::AppKit::Plugin::AppKit::FeatureList;
use experimental 'smartmatch';
with 'Catalyst::ClassData';

###########################################################################################################################
# moose calls.
###########################################################################################################################

has appkit_controllers => ( is => 'ro',    isa => 'ArrayRef',  lazy_build => 1 );
sub _build_appkit_controllers
{   
    my ( $c ) = shift;

    my @controllers;

    # Get all the components for this app... sorted by length of the name of the componant so they are in hierarchical order (bit hacky, but think it should work)
    foreach my $comp ( sort { length($a) <=> length($b) } values %{ $c->components } )
    {   
        # Check this is a controller for AppKit.... (not sure if we need to ignore others, but it just seems cleaner)..
        if  (
                ( $comp->isa('Catalyst::Controller')    )               &&
                ( $comp->can('appkit') )
            )
        {   
            push( @controllers, $comp );
        }
    }
    return \@controllers;
}

sub apps_allowed
{
    my $self = shift;
    # return a sorted list of appkit controllers the user can use.
    return sort { $a->appkit_order <=> $b->appkit_order } 
            grep { $_->home_action && $self->can_access($_->home_action->{actionpath}) } @{$self->appkit_controllers};
}

sub menu_data
{
    # rip through the apps and construct an array of apps containing the 
    # group info too.
    my $self = shift;

    my @apps = sort { ($a->appkit_shared_module || '') cmp ($b->appkit_shared_module || '') || $b->appkit_order <=> $a->appkit_order } 
            @{$self->appkit_controllers};
    # now merge together the grouped controllers.
    my $i = 0;
    while($i + 1 < scalar @apps)
    {
        if($apps[$i]->appkit_shared_module && $apps[$i+1]->appkit_shared_module && 
            ($apps[$i]->appkit_shared_module eq $apps[$i+1]->appkit_shared_module))
        {
            splice @apps, $i + 1, 1;
        }
        else
        {
            $i++;
        }
    }
    @apps = sort { $a->appkit_order <=> $b->appkit_order } @apps;
    my $menu = [];

    for my $app (@apps)
    {
        my $actions = $app->application_action_list($self);
        if(@$actions)
        {
            push @$menu, { controller => $app, actions => $actions };



( run in 0.772 second using v1.01-cache-2.11-cpan-39bf76dae61 )