Web-Components
view release on metacpan or search on metacpan
lib/Web/Components/ConfigLoader.pm view on Meta::CPAN
predicate => 'has_local_config_file';
sub _config_file_list ($) {
my $attr = shift;
(my $name = lc $attr->{appclass}) =~ s{ :: }{-}gmx;
my $file = $attr->{config_file}
// ns_environment($attr->{appclass}, 'config')
// $name;
my $extensions = $attr->{config_extensions} // 'json yaml';
return map { "${file}.${_}" } split m{ \s }mx, $extensions;
}
sub _home_indicator_dirs () {
return qw( var );
}
sub _dist_indicator_files () {
return qw( Makefile.PL Build.PL dist.ini cpanfile );
}
lib/Web/Components/Loader.pm view on Meta::CPAN
$self->log->error($e);
return [ HTTP_INTERNAL_SERVER_ERROR, _header, [$e] ];
}
sub _parse_sig {
my ($self, $args) = @_;
return @{$args} if exists $self->models->{$args->[0]};
my ($moniker, $method) = split m{ / }mx, $args->[0], 2;
if (exists $self->models->{$moniker}) {
shift @{$args};
return $moniker, $method, @{$args};
}
return;
}
sub _recognise_signature {
my ($self, $args) = @_;
return 1 if is_arrayref $args and $args->[0]
and exists $self->models->{$args->[0]};
my ($moniker, $method) = split m{ / }mx, $args->[0], 2;
return 1 if $moniker and exists $self->models->{$moniker};
return 0;
}
sub _redirect {
my ($self, $context) = @_;
my $req = $context->request;
lib/Web/Components/Model.pm view on Meta::CPAN
my ($self, $context, $methods) = @_;
my $stash = $context->stash;
my $nav_key = $self->navigation_key;
my $options = { optional => TRUE, scrubber => FALSE };
my $uri_args = $context->request->uri_params->($options);
my $last_method;
$stash->{method_chain} = $methods;
for my $method (split m{ / }mx, $methods) {
my $coderef = $self->can($method)
or throw UnknownMethod, [blessed $self, $method];
$method = NUL unless $self->is_authorised($context, $coderef);
$self->$method($context, @{$uri_args}) if $method;
return $stash->{response} if $stash->{response};
$stash->{$nav_key}->finalise_script_request if exists $stash->{$nav_key};
lib/Web/Components/Navigation.pm view on Meta::CPAN
label. This is appended to C<title_abbrev> to form the labels in the browser
history
=cut
has 'title_entry' =>
is => 'lazy',
isa => Str,
default => sub {
my $self = shift;
my @parts = split m{ / }mx, $self->context->action;
my $label = $self->_get_nav_label($parts[0] . '/' . $parts[-1]);
return (split m{ \| }mx, $label)[0] // NUL;
};
# Private attributes
has '_base_url' =>
is => 'lazy',
isa => class_type('URI'),
default => sub {
return shift->context->request->uri_for(NUL);
};
lib/Web/Components/Navigation.pm view on Meta::CPAN
$label = shift @args;
$label->{name} = $self->_get_nav_label($args[0]);
}
else { $label = $self->_get_nav_label($args[0]) }
if ($self->model->is_authorised($self->context, $args[0])) {
my $list = $self->_lists->{$self->_name}->[1];
my ($text, $icon);
if (is_hashref $label) {
($text, $icon) = split m{ \| }mx, $label->{name};
$label->{name} = $text;
$text = $label;
}
else { ($text, $icon) = split m{ \| }mx, $label }
$icon = $self->context->request->uri_for($icon)
if $icon && $icon =~ m{ / }mx;
push @{$list}, [$text => $self->_uri(@args), $icon];
}
else { clear_redirect $self->context }
return $self;
}
lib/Web/Components/Navigation.pm view on Meta::CPAN
return $output;
}
# Private methods
sub _add_global {
my $self = shift;
my $list = $self->list('_global');
for my $action (@{$self->global}) {
my ($moniker, $method) = split m{ / }mx, $action;
if ($self->model->is_authorised($self->context, $action)) {
if ($method and $method eq 'menu') {
$self->context->models->{$moniker}->menu($self->context);
$self->_set__name('_global');
}
push @{$self->_lists->{$self->_name}->[1]}, $moniker
if exists $self->_lists->{$moniker};
lib/Web/Components/ReverseMap.pm view on Meta::CPAN
source
=cut
has 'action_path_map' => is => 'lazy', isa => HashRef, default => sub {
my $self = shift;
my $class = blessed $self;
my $map = {};
for my $pair (pairs $self->dispatch_request) {
my @parts = split m{ / }mx, $pair->value->()->[0];
my $action = $parts[0] . '/' . $parts[-1];
my ($uri) = $pair->key =~ m{ [\+] \s* / ([^\+]+) }mx;
next unless $uri;
$uri =~ s{ [ ]+ \z }{}mx;
$uri = [ split m{ \s+? \| \s+? /? }mx, $uri ] if $uri =~ m{ \| }mx;
$map->{$action} = $uri;
}
$self->log->warn("No routes found in ${class}") unless scalar keys %{$map};
return $map;
};
=back
lib/Web/Components/Util.pm view on Meta::CPAN
my $appclass = deref $config, 'appclass';
# The config object/hash ref is required. It must have an appclass attribute
# uncoverable branch true
throw(Unspecified, ['config appclass']) unless $appclass;
my $search_path;
if (first_char $base eq '+') { $search_path = $base = substr $base, 1 }
else { $search_path = "${appclass}::${base}" }
my $depth = () = split m{ :: }mx, $search_path, -1;
$depth += 1;
my $finder = Module::Pluggable::Object->new(
max_depth => $depth,
min_depth => $depth,
search_path => [$search_path],
require => TRUE,
);
my $compos = $opts->{components} //= {}; # Dependency injection
( run in 1.208 second using v1.01-cache-2.11-cpan-71847e10f99 )