| 1 | package WWW::FBX::API; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 24 | ▶ | use 5.014001; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 24 | ▶ | use Moose(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 24 | ▶ | use Carp::Clan qw/^(?:WWW::FBX|Moose|Class::MOP)/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 24 | ▶ | use Moose::Exporter; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 24 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 24 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 24 | Moose::Exporter->setup_import_methods( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | with_caller => [ qw/api_url fbx_api_method/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 24 | my $_api_url; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub api_url { $_api_url = $_[1]; } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
api_url: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2370 | ▶ | sub fbx_api_method { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fbx_api_method: called CC=1 SCAR=5.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2370 | my $caller = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2370 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2370 | my %options = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | @_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2370 | my $args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #Remove trailing _ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2370 | $name =~ s/_$//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2370 | my $class = Moose::Meta::Class->initialize($caller); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2370 | my ($arg_names, $all_args) = @options{qw/required params/}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my $code = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wol_host: not called CC=11 SCAR=48.8
Subroutine
dhcp_static_lease: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $args = ref $_[-1] eq 'HASH' ? { %{pop @_} } : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | croak sprintf "$name expected %d args", scalar @$all_args if @_ > @$all_args; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # promote positional args to named args | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | for ( my $i = 0; @_; ++$i ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $param = $all_args->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | croak "duplicate param $param: both positional and named" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if exists $args->{$param}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $args->{$param} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | for my $arg (keys %$args) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | unless ( grep { $_ eq $arg } @$all_args ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | die "Unknown argument $arg for $name\n" , "Description:$options{description}" , | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | "Params:", join(",",@$all_args), "\nRequired:", join(",", @$arg_names), "\n" ; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | for my $req (@$arg_names) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | unless ( grep { $_ eq $req } keys %$args or !defined ($args->{req}) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
grep {$_ eq $req;} keys %$args or not defined $args->{"req"}
grep {$_ eq $req;} keys %$args or not defined $args->{"req"}
MC/DC0%0/2
grep {$_ eq $req;} keys %$args or not defined $args->{"req"}
grep {$_ eq $req;} keys %$args
not defined $args->{"req"}
MC/DC0%0/2
grep {$_ eq $req;} keys %$args or not defined $args->{"req"}
grep {$_ eq $req;} keys %$args
not defined $args->{"req"}
Truth table0%0/3
A or not(B)
A= grep {$_ eq $req;} keys %$argsB= not defined $args->{"req"}
Truth table0%0/3
A or not(B)
A= grep {$_ eq $req;} keys %$argsB= not defined $args->{"req"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | die "Missing required param $req for $name\n", "Description:$options{description}" , | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | "Params:", join(",",@$all_args), "\nRequired:", join(",", @$arg_names), "\n" ; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $path = $options{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $path .= delete $args->{suff} if exists $args->{suff}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $uri = URI->new( $self->base_url . "$_api_url/$path"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | return $self->_json_request( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | $options{method}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | $args, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | $options{content_type} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2370 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | #Add method with name and Class::MOP::Method | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2370 | $class->add_method( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | WWW::FBX::Meta::Method->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | package_name => $caller, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | body => $code, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | %options, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | package WWW::FBX::Meta::Method; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 24 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 24 | ▶ | use Carp::Clan qw/^(?:WWW::FBX|Moose|Class::MOP)/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 24 | extends 'Moose::Meta::Method'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 24 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 24 | has description => ( isa => 'Str', is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 24 | has path => ( isa => 'Str', is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 24 | has method => ( isa => 'Str', is => 'ro', default => 'GET' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | has params => ( isa => 'ArrayRef[Str]', is => 'ro', default => sub { [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | has required => ( isa => 'ArrayRef[Str]', is => 'ro', default => sub { [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 24 | has returns => ( isa => 'Str', is => 'ro', predicate => 'has_returns' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 24 | has content_type => ( isa => 'Str', is => 'ro', default => '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 24 | has suff => ( isa => 'Str', is => 'ro', default => '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | #Build hash where keys are attribute names | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 24 | my %valid_attribute_names = map { $_->init_arg => 1 } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | __PACKAGE__->meta->get_all_attributes; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 2370 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 2370 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 2370 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | #Stack arguments that are not expected attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2370 | my @invalid_attributes = grep { !$valid_attribute_names{$_} } keys %args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2370 | ▶ | croak "unexpected argument(s): @invalid_attributes" if @invalid_attributes; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | #Create method | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2370 | $class->SUPER::wrap(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 24 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||