Commit | Line | Data |
5b2d23f3 |
1 | #!/usr/bin/perl |
2 | |
3 | package Bench::Accessor; |
4 | use Moose; |
5 | use Moose::Util::TypeConstraints; |
6 | |
7 | eval { |
8 | coerce ArrayRef |
9 | => from HashRef |
10 | => via { [ %$_ ] }; |
11 | }; |
12 | |
13 | has class => ( |
14 | isa => "Str", |
15 | is => "ro", |
16 | ); |
17 | |
18 | has construct => ( |
19 | isa => "ArrayRef", |
20 | is => "ro", |
21 | auto_deref => 1, |
22 | coerce => 1, |
23 | ); |
24 | |
25 | has accessor => ( |
26 | isa => "Str", |
27 | is => "ro", |
28 | ); |
29 | |
30 | has accessor_args => ( |
31 | isa => "ArrayRef", |
32 | is => "ro", |
33 | auto_deref => 1, |
34 | coerce => 1, |
35 | ); |
36 | |
37 | sub code { |
38 | my $self = shift; |
39 | |
40 | my $obj = $self->class->new( $self->construct ); |
41 | my @accessor_args = $self->accessor_args; |
42 | my $accessor = $self->accessor; |
43 | |
44 | sub { $obj->$accessor( @accessor_args ) }; |
45 | } |
46 | |
47 | __PACKAGE__; |
48 | |
49 | __END__ |