| 1 | package MouseX::Param; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use 5.8.1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use Mouse::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | our $VERSION = '0.01'; | |||||||||
| 7 | |||||||||||
| 8 | has 'params' => ( | ||||||||||
| 9 | is => 'rw', | ||||||||||
| 10 | isa => 'HashRef', | ||||||||||
| 11 | lazy => 1, | ||||||||||
| 12 | 1 | ▶ | default => sub { +{} }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ); | |||||||||
| 14 | |||||||||||
| 15 | 6 | ▶ | sub param { | ||||||||
|
Subroutine
param: called CC=4 SCAR=17.2
Pod
documented
| |||||||||||
| 16 | 6 | my $self = shift; | |||||||||
| 17 | |||||||||||
| 18 | 6 | ▶ | return keys %{ $self->params } if @_ == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 3 | ▶ | return $self->params->{+shift} if @_ == 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | |||||||||||
| 21 | 0 | my %params = @_; | |||||||||
| 22 | 0 | ▶ | while (my ($key, $value) = each %params) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | $self->params->{$key} = $value; | |||||||||
| 24 | } | ||||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 2 | ▶ | no Mouse::Role; 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | ||||||||||