|
Revision 28318, 1.3 kB
(checked in by masaki, 4 years ago)
|
|
initial import
|
| Line | |
|---|
| 1 | package MouseX::Param; |
|---|
| 2 | |
|---|
| 3 | use 5.8.1; |
|---|
| 4 | use Mouse::Role; |
|---|
| 5 | |
|---|
| 6 | our $VERSION = '0.01'; |
|---|
| 7 | |
|---|
| 8 | has 'params' => ( |
|---|
| 9 | is => 'rw', |
|---|
| 10 | isa => 'HashRef', |
|---|
| 11 | lazy => 1, |
|---|
| 12 | default => sub { +{} }, |
|---|
| 13 | ); |
|---|
| 14 | |
|---|
| 15 | sub param { |
|---|
| 16 | my $self = shift; |
|---|
| 17 | |
|---|
| 18 | return keys %{ $self->params } if @_ == 0; |
|---|
| 19 | return $self->params->{+shift} if @_ == 1; |
|---|
| 20 | |
|---|
| 21 | my %params = @_; |
|---|
| 22 | while (my ($key, $value) = each %params) { |
|---|
| 23 | $self->params->{$key} = $value; |
|---|
| 24 | } |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | no Mouse::Role; 1; |
|---|
| 28 | |
|---|
| 29 | =head1 NAME |
|---|
| 30 | |
|---|
| 31 | MouseX::Param - A Mouse role for manipulating params |
|---|
| 32 | |
|---|
| 33 | =head1 SYNOPSIS |
|---|
| 34 | |
|---|
| 35 | package MyApp; |
|---|
| 36 | use Mouse; |
|---|
| 37 | with 'MouseX::Param'; |
|---|
| 38 | |
|---|
| 39 | package main; |
|---|
| 40 | |
|---|
| 41 | my $app = MyApp->new(params => { |
|---|
| 42 | foo => 10, |
|---|
| 43 | bar => 20, |
|---|
| 44 | }); |
|---|
| 45 | |
|---|
| 46 | # getting params |
|---|
| 47 | $app->param('foo'); # 10 |
|---|
| 48 | |
|---|
| 49 | # getting list of params |
|---|
| 50 | $app->param(); # foo, bar |
|---|
| 51 | |
|---|
| 52 | # setting params |
|---|
| 53 | $app->param(foo => 30, bar => 40); |
|---|
| 54 | |
|---|
| 55 | =head1 DESCRIPTION |
|---|
| 56 | |
|---|
| 57 | MouseX::Param is a simple Mouse role which provides a L<CGI> like |
|---|
| 58 | C<param> method. |
|---|
| 59 | |
|---|
| 60 | =head1 METHODS |
|---|
| 61 | |
|---|
| 62 | =head2 param |
|---|
| 63 | |
|---|
| 64 | =head1 PROPERTIES |
|---|
| 65 | |
|---|
| 66 | =head2 params |
|---|
| 67 | |
|---|
| 68 | =head1 AUTHOR |
|---|
| 69 | |
|---|
| 70 | NAKAGAWA Masaki E<lt>masaki@cpan.orgE<gt> |
|---|
| 71 | |
|---|
| 72 | =head1 THANKS TO |
|---|
| 73 | |
|---|
| 74 | Stevan Little, L<MooseX::Param/AUTHOR> |
|---|
| 75 | |
|---|
| 76 | =head1 LICENSE |
|---|
| 77 | |
|---|
| 78 | This library is free software; you can redistribute it and/or modify |
|---|
| 79 | it under the same terms as Perl itself. |
|---|
| 80 | |
|---|
| 81 | =head1 SEE ALSO |
|---|
| 82 | |
|---|
| 83 | L<Mouse>, L<MooseX::Param> |
|---|
| 84 | |
|---|
| 85 | =cut |
|---|