antmico has asked for the wisdom of the Perl Monks concerning the following question:
package Button; use Moose; use namespace::autoclean; use XML::Writer; has 'name' => ( is => 'rw', isa => 'Str', required => 1); has 'x' => ( is => 'rw', isa => 'Int', predicate => 'has_x'); has 'y' => ( is => 'rw', isa => 'Int', predicate => 'has_y'); has 'w' => ( is => 'rw', isa => 'Int', predicate => 'has_w'); has 'h' => ( is => 'rw', isa => 'Int', predicate => 'has_h'); sub to_xml { my ($self) = @_; my %attr; $attr{name} = $self->name; $attr{x} = $self->x if $self->has_x; $attr{y} = $self->y if $self->has_y; $attr{w} = $self->w if $self->has_w; $attr{h} = $self->h if $self->has_h; my $writer = XML::Writer->new( OUTPUT => 'self' ); $writer->emptyTag('button', %attr); return $writer->to_string; } __PACKAGE__->meta->make_immutable;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose attribute predicate alternative
by choroba (Cardinal) on Jul 04, 2013 at 13:16 UTC | |
by tobyink (Canon) on Jul 04, 2013 at 14:35 UTC | |
by hdb (Monsignor) on Jul 04, 2013 at 14:46 UTC | |
by Anonymous Monk on Jul 04, 2013 at 15:35 UTC | |
by antmico (Novice) on Jul 04, 2013 at 15:53 UTC | |
|
Re: Moose attribute predicate alternative
by tobyink (Canon) on Jul 04, 2013 at 14:36 UTC |