| 1 | package WP::API::Post; | ||||||||||||
| 2 | { | ||||||||||||
| 3 | 5 | $WP::API::Post::VERSION = '0.01'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | 5 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 5 | $WP::API::Post::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 | use WP::API::Types | ||||||||||||
| 14 | 5 | ▶ | qw( ArrayRef Bool HashRef Maybe NonEmptyStr PositiveInt PositiveOrZeroInt Uri ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | |||||||||||||
| 16 | 5 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 5 | ▶ | use MooseX::StrictConstructor; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | 5 | my %fields = ( | |||||||||||
| 20 | post_type => NonEmptyStr, | ||||||||||||
| 21 | post_status => NonEmptyStr, | ||||||||||||
| 22 | post_title => NonEmptyStr, | ||||||||||||
| 23 | post_author => PositiveInt, | ||||||||||||
| 24 | post_excerpt => Maybe [NonEmptyStr], | ||||||||||||
| 25 | post_content => NonEmptyStr, | ||||||||||||
| 26 | post_date_gmt => 'DateTime', | ||||||||||||
| 27 | post_date => 'DateTime', | ||||||||||||
| 28 | post_modified_gmt => 'DateTime', | ||||||||||||
| 29 | post_modified => 'DateTime', | ||||||||||||
| 30 | post_format => NonEmptyStr, | ||||||||||||
| 31 | post_name => NonEmptyStr, | ||||||||||||
| 32 | post_password => Maybe [NonEmptyStr], | ||||||||||||
| 33 | comment_status => NonEmptyStr, | ||||||||||||
| 34 | ping_status => NonEmptyStr, | ||||||||||||
| 35 | sticky => Bool, | ||||||||||||
| 36 | post_thumbnail => HashRef, | ||||||||||||
| 37 | post_parent => PositiveOrZeroInt, | ||||||||||||
| 38 | post_mime_type => Maybe [NonEmptyStr], | ||||||||||||
| 39 | link => Uri, | ||||||||||||
| 40 | guid => Uri, | ||||||||||||
| 41 | menu_order => PositiveOrZeroInt, | ||||||||||||
| 42 | custom_fields => ArrayRef [HashRef], | ||||||||||||
| 43 | terms => ArrayRef [HashRef], | ||||||||||||
| 44 | enclosure => HashRef, | ||||||||||||
| 45 | ); | ||||||||||||
| 46 | |||||||||||||
| 47 | 5 | with 'WP::API::Role::WPObject' => { | |||||||||||
| 48 | id_method => 'post_id', | ||||||||||||
| 49 | xmlrpc_get_method => 'wp.getPost', | ||||||||||||
| 50 | xmlrpc_create_method => 'wp.newPost', | ||||||||||||
| 51 | fields => \%fields, | ||||||||||||
| 52 | }; | ||||||||||||
| 53 | |||||||||||||
| 54 | 1 | ▶ | sub _munge_create_parameters { | ||||||||||
|
Subroutine
_munge_create_parameters: called CC=2 SCAR=7.0
| |||||||||||||
| 55 | 1 | my $class = shift; | |||||||||||
| 56 | 1 | my $p = shift; | |||||||||||
| 57 | |||||||||||||
| 58 | 1 | ▶ | $p->{post_status} //= 'publish'; | ||||||||||
|
Condition50%1/2
$p->{"post_status"} //= "publish"
MC/DC0%0/1
$p->{"post_status"} //= "publish"
$p->{"post_status"}
Truth table50%1/2
A
A= $p->{"post_status"}
| |||||||||||||
| 59 | |||||||||||||
| 60 | 1 | $class->_deflate_datetimes( | |||||||||||
| 61 | $p, | ||||||||||||
| 62 | 'post_date_gmt', 'post_date', | ||||||||||||
| 63 | 'post_modified_gmt', 'post_modified', | ||||||||||||
| 64 | ); | ||||||||||||
| 65 | |||||||||||||
| 66 | 1 | return; | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | 1 | ▶ | sub _create_result_as_params { | ||||||||||
|
Subroutine
_create_result_as_params: called CC=1 SCAR=0.0
| |||||||||||||
| 70 | 1 | my $class = shift; | |||||||||||
| 71 | 1 | my $p = shift; | |||||||||||
| 72 | |||||||||||||
| 73 | 1 | return ( post_id => $p ); | |||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | 1 | ▶ | sub _munge_raw_data { | ||||||||||
|
Subroutine
_munge_raw_data: called CC=2 SCAR=6.9
| |||||||||||||
| 77 | 1 | my $self = shift; | |||||||||||
| 78 | 1 | my $p = shift; | |||||||||||
| 79 | |||||||||||||
| 80 | # WordPress 3.5 seems to return an array instead of a struct when the post | ||||||||||||
| 81 | # has no thumbnail. | ||||||||||||
| 82 | { | ||||||||||||
| 83 | 1 | local $@; | |||||||||||
| 84 | 1 | ▶ | if ( eval { my $foo = @{ $p->{post_thumbnail} }; 1 } ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | 1 | $p->{post_thumbnail} = {}; | |||||||||||
| 86 | } | ||||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | 1 | return; | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | 5 | __PACKAGE__->meta()->make_immutable(); | |||||||||||
| 93 | |||||||||||||
| 94 | 5 | 1; | |||||||||||
| 95 | |||||||||||||
| 96 | # ABSTRACT: An interface for WordPress post objects | ||||||||||||
| 97 | |||||||||||||
| 98 | __END__ | ||||||||||||