use namespace::clean -except => [ qw(meta) ];
+has target_model => (
+ is => 'ro',
+ required => 1,
+ metaclass => 'Reaction::Meta::Attribute'
+);
+
+has ctx => (
+ isa => 'Catalyst',
+ is => 'ro',
+ lazy_fail => 1,
+ metaclass => 'Reaction::Meta::Attribute',
+ weak_ref => 1,
+);
-has target_model => (is => 'ro', required => 1,
- metaclass => 'Reaction::Meta::Attribute');
-
-has ctx => (isa => 'Catalyst', is => 'ro', lazy_fail => 1,
- metaclass => 'Reaction::Meta::Attribute');
sub parameter_attributes {
shift->meta->parameter_attributes;
-};
+}
+
sub parameter_hashref {
my ($self) = @_;
my %params;
foreach my $attr ($self->parameter_attributes) {
my $reader = $attr->get_read_method;
my $predicate = $attr->get_predicate_method;
- next if defined($predicate) && !$self->$predicate;
+ next if defined($predicate) && !$self->$predicate
+ && ($attr->is_lazy_fail || !$attr->has_default);
$params{$attr->name} = $self->$reader;
}
return \%params;
-};
+}
+
sub can_apply {
my ($self) = @_;
foreach my $attr ($self->parameter_attributes) {
my $predicate = $attr->get_predicate_method;
if ($self->attribute_is_required($attr)) {
- return 0 unless $self->$predicate;
+ confess "No predicate for required attribute ${\$attr->name} for ${self}"
+ unless $predicate;
+ return 0 if !$self->$predicate && ($attr->is_lazy_fail || !$attr->has_default);
}
if ($attr->has_valid_values) {
unless ($predicate && !($self->$predicate)) {