Catalyst-Runtime

 view release on metacpan or  search on metacpan

lib/Catalyst.pm  view on Meta::CPAN

    ) {
        warn("You made your application class ($class) immutable, "
            . "but did not inline the\nconstructor. "
            . "This will break catalyst, as your app \@ISA "
            . "Class::Accessor(::Fast)?\nPlease pass "
            . "(replace_constructor => 1)\nwhen making your class immutable.\n");
    }
    unless ($meta->is_immutable) {
        # XXX - FIXME warning here as you should make your app immutable yourself.
        $meta->make_immutable(
            replace_constructor => 1,
        );
    }
}

=head2 $c->set_action( $action, $code, $namespace, $attrs )

Sets an action in a given namespace.

=cut

sub set_action { my $c = shift; $c->dispatcher->set_action( $c, @_ ) }

=head2 $c->setup_actions($component)

Sets up actions for a component.

=cut

sub setup_actions { my $c = shift; $c->dispatcher->setup_actions( $c, @_ ) }

=head2 $c->setup_components

This method is called internally to set up the application's components.

It finds modules by calling the L<locate_components> method, expands them to
package names with the L<expand_component_module> method, and then installs
each component into the application.

The C<setup_components> config option is passed to both of the above methods.

Installation of each component is performed by the L<setup_component> method,
below.

=cut

sub setup_components {
    my $class = shift;

    my $config  = $class->config->{ setup_components };

    my @comps = $class->locate_components($config);

    my $deprecatedcatalyst_component_names = grep { /::[CMV]::/ } @comps;
    $class->log->warn(qq{Your application is using the deprecated ::[MVC]:: type naming scheme.\n}.
        qq{Please switch your class names to ::Model::, ::View:: and ::Controller: as appropriate.\n}
    ) if $deprecatedcatalyst_component_names;

    for my $component ( @comps ) {

        # We pass ignore_loaded here so that overlay files for (e.g.)
        # Model::DBI::Schema sub-classes are loaded - if it's in @comps
        # we know M::P::O found a file on disk so this is safe

        Catalyst::Utils::ensure_class_loaded( $component, { ignore_loaded => 1 } );
    }

    for my $component (@comps) {
        my $instance = $class->components->{ $component } = $class->delayed_setup_component($component);
    }

    # Inject a component or wrap a stand alone class in an adaptor. This makes a list
    # of named components in the configuration that are not actually existing (not a
    # real file).

    my @injected = $class->setup_injected_components;

    # All components are registered, now we need to 'init' them.
    foreach my $component_name (@comps, @injected) {
      $class->components->{$component_name} = $class->components->{$component_name}->() if
        (ref($class->components->{$component_name}) || '') eq 'CODE';
    }
}

=head2 $app->setup_injected_components

Called by setup_compoents to setup components that are injected.

=cut

sub setup_injected_components {
    my ($class) = @_;
    my @injected_components = keys %{$class->config->{inject_components} ||+{}};

    foreach my $injected_comp_name(@injected_components) {
        $class->setup_injected_component(
          $injected_comp_name,
          $class->config->{inject_components}->{$injected_comp_name});
    }

    return map { $class ."::" . $_ }
      @injected_components;
}

=head2 $app->setup_injected_component( $injected_component_name, $config )

Setup a given injected component.

=cut

sub setup_injected_component {
    my ($class, $injected_comp_name, $config) = @_;
    if(my $component_class = $config->{from_component}) {
        my @roles = @{$config->{roles} ||[]};
        Catalyst::Utils::inject_component(
          into => $class,
          component => $component_class,
          (scalar(@roles) ? (traits => \@roles) : ()),
          as => $injected_comp_name);
    }
}



( run in 3.641 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )