name 'CatalystX-Declare';
author 'Robert Sedlacek <rs@474.at>';
license 'perl';
+version '0.015';
all_from 'lib/CatalystX/Declare.pm';
readme_from 'lib/CatalystX/Declare.pm';
requires 'MooseX::Types', '0.20';
requires 'MooseX::Method::Signatures', '0.26';
requires 'Catalyst::Controller::ActionRole', '0.15';
+requires 'Data::Pond', '0.002';
requires 'FindBin';
test_requires 'Test::More', '0.92';
clean;
- our $VERSION = '0.014';
+ our $VERSION = '0.015';
around keywords (ClassName $self:) {
$self->$orig,
with CatalystX::Declare::Controller::QualifyClassNames {
around create_action (%args) {
-
my ($action_class) = @{ $args{attributes}{CatalystX_Declarative_ActionClass} || [] };
$action_class ||= 'Catalyst::Action';
Moose::Meta::Class->initialize($fq_class);
$args{attributes}{ActionClass} ||= [$fq_class];
-
return $self->$orig(%args);
}
}
use Data::Dump qw( pp );
use MooseX::Types::Util qw( has_available_type_export );
use Moose::Util qw( add_method_modifier ensure_all_roles );
+ use Data::Pond qw(pond_write_datum);
use Class::Inspector;
use Class::MOP;
next if $attr eq 'Chained' and $value eq UNDER_VAR;
push @attributes,
- map { sprintf '%s%s', $attr, defined($_) ? sprintf('(%s)', $_) : '' }
- (ref($value) eq 'ARRAY')
- ? @$value
- : $value;
+ map {
+ my $value = ref $_ ? pond_write_datum($_) : $_;
+ sprintf '%s%s', $attr, defined($value) ? sprintf('(%s)', $value) : ''
+ } (
+ ref($value) eq 'ARRAY'
+ ) ? @$value : $value;
}
return \@attributes;
# merge runtime and compiletime attrs
my %full_attrs = (%attributes, %$attrs);
my $compiled_attrs = $compile_attrs->(\%full_attrs);
-
my $real_method = $method->reify(
actual_body => $body,
attributes => $compiled_attrs,
# NYI
if ($modifier) {
-
add_method_modifier $class, $modifier, [$name, $real_method];
- }
- else {
+ } else {
my $prepare_meta = sub {
my ($meta) = @_;
my ($first, @rest) = eval $params;
my %params = ref $first eq 'HASH' ? %$first : ($first, @rest); # both (%opts) and {%opts}
for my $key (keys %params) {
- my $parameters = ref $params{$key} eq 'ARRAY' ? @{$params{$key}} : $params{$key};
- push @{$attrs->{$key}}, $parameters;
+ my $value = ref $params{$key} eq 'ARRAY' ? $params{$key} : [$params{$key}];
+ push @{ $attrs->{$key} ||=[] }, @$value;
+ ##push @{ $attrs->{$key} ||=[] }, $params;
+
}
}
}
push @{ $attrs->{CatalystX_Declarative_ActionRoles} ||= [] }, @roles;
-
return;
}
is get('/actionparams/first'), 'action_args_first: 100,101', 'actionrole with params';
is get('/actionparams/second'), 'action_args_second: 200,201', 'actionrole with params (part two)';
is get('/actionparams/third'), 'action_args_third: 300,301', 'actionrole with params (part three)';
-is get('/actionparams/forth'), 'action_args_forth: 400,1,401,2', 'actionrole with params (part four)';
+is get('/actionparams/forth'), 'action_args_forth: 400,1,401,2', 'actionrole with params (part four)';
is get('/actionparams/first_app_ns'), 'action_args_first: 100,101', 'actionrole with params (from App NS)';
is get('/actionparams/first_cat_ns'), 'action_args_first: 100,101', 'actionrole with params (from Cat NS)';
+# Check deep parsing
+is get('/actionparams/check_deep'), 'action_args_deep: {a=>1,b=>2}', 'actionrole with deep params';
+
done_testing;
}
}
+role hasActionParamsDeep {
+ has 'p_deep' => (is=>'ro', lazy_build=>1);
+ method _build_p_deep {
+ join ',', @{$self->attributes->{p_deep}};
+ }
+}
+
controller ::Controller::ActionParams {
action base
}
action forth under base
- with (hasActionParams(
- p1=>400,
- p2=>401,
- ), hasActionParams(p1=>1,p2=>2)) is final {
- my $p1 = $ctx->controller->action_for('forth')->p1;
- my $p2 = $ctx->controller->action_for('forth')->p2;
+ with (
+ hasActionParams(p1=>400,p2=>401),
+ hasActionParams(p1=>1,p2=>2, p0=>3)
+ ) is final {
+ my $action = $ctx->controller->action_for('forth');
+ my $p1 = $action->p1;
+ my $p2 = $action->p2;
$ctx->response->body("action_args_forth: $p1,$p2");
}
$ctx->response->body("action_args_first: $p1,$p2");
}
+ action check_deep under base
+ with hasActionParamsDeep(p_deep=>{a=>1,b=>2}) is final {
+ my $action = $ctx->controller->action_for('check_deep');
+ my $p_deep = $action->p_deep;
+ ## $ctx->log->_dump($action->attributes);
+ $ctx->response->body("action_args_deep: $p_deep");
+ }
+
+
}