| 1 | package WP::API::WrappedClass; | ||
| 2 | { | ||
| 3 | 5 | $WP::API::WrappedClass::VERSION = '0.01'; | |
| 4 | } | ||
| 5 | 5 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 5 | $WP::API::WrappedClass::AUTHORITY = 'cpan:DROLSKY'; | |
| 7 | } | ||
| 8 | |||
| 9 | 5 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 5 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 5 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | 5 | ▶ | use WP::API::Types qw( ClassName ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | |||
| 15 | 5 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | 5 | ▶ | use MooseX::StrictConstructor; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | |||
| 18 | 5 | has api => ( | |
| 19 | is => 'ro', | ||
| 20 | isa => 'WP::API', | ||
| 21 | required => 1, | ||
| 22 | ); | ||
| 23 | |||
| 24 | 5 | has class => ( | |
| 25 | is => 'ro', | ||
| 26 | isa => ClassName, | ||
| 27 | required => 1, | ||
| 28 | ); | ||
| 29 | |||
| 30 | 5 | our $AUTOLOAD; | |
| 31 | |||
| 32 | 2 | ▶ | sub AUTOLOAD { |
|
Subroutine
AUTOLOAD: called CC=1 SCAR=0.0
| |||
| 33 | 2 | my $self = shift; | |
| 34 | |||
| 35 | 2 | my ($method) = $AUTOLOAD =~ /::(\w+)$/; | |
| 36 | |||
| 37 | 2 | return $self->class()->$method( api => $self->api(), @_ ); | |
| 38 | } | ||
| 39 | |||
| 40 | 5 | __PACKAGE__->meta()->make_immutable(); | |
| 41 | |||
| 42 | # This is hack so we can make an immutablized constructor - Moose will not | ||
| 43 | # rename the constructor as part of inlining. | ||
| 44 | 5 | *wrap = \&new; | |
| 45 | |||
| 46 | 5 | Package::Stash->new(__PACKAGE__)->remove_symbol('&new'); | |
| 47 | |||
| 48 | # Now we want ->new to call the method on the wrapped class, not on | ||
| 49 | # WrappedClass itself. | ||
| 50 | Package::Stash->new(__PACKAGE__)->add_symbol( | ||
| 51 | 2 | ▶ | '&new' => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 52 | 2 | my $self = shift; | |
| 53 | |||
| 54 | 2 | $self->class()->new( api => $self->api(), @_ ); | |
| 55 | } | ||
| 56 | 5 | ); | |
| 57 | |||
| 58 | 5 | 1; | |
| 59 | |||
| 60 | # ABSTRACT: A shim to pass the WP::API object to Post/Media/etc objects | ||
| 61 | |||
| 62 | __END__ | ||