File Coverage

blib/lib/WebService/ValidSign/Object.pm
Criterion Covered Total %
statement 24 25 96.0
branch 14 18 77.7
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 42 48 87.5


line stmt bran cond sub pod time code
1             package WebService::ValidSign::Object;
2             our $VERSION = '0.003';
3 4     4   2072 use Moo;
  4         9  
  4         21  
4              
5             # ABSTRACT: A ValidSign object in use for the API
6              
7 4     4   1333 use Types::Standard qw(Str);
  4         12  
  4         26  
8 4     4   3564 use String::CamelSnakeKebab qw(lower_camel_case lower_snake_case);
  4         48707  
  4         31  
9              
10             has id => (
11             is => 'rw',
12             isa => Str,
13             predicate => 'has_id'
14             );
15              
16             has type => (
17             is => 'ro',
18             isa => Str,
19             required => 1,
20             );
21              
22             around BUILDARGS => sub {
23             my $orig = shift;
24             my $class = shift;
25             my %args = @_;
26              
27             return $orig->($class,
28             map { lower_snake_case($_) => $args{$_} } keys %args);
29             };
30              
31             sub TO_JSON {
32 8     8 0 814 my $self = shift;
33 8         64 my $meta = $self->meta;
34 8         122 my %result;
35 8         76 for my $attr ($meta->get_all_attributes) {
36 61         1238667 my $name = $attr->name;
37 61         206 my $value = $attr->get_value($self);
38 61         9839 my $type = $attr->type_constraint;
39              
40 61 100       568 if ($type) {
41 48 100       338 if ($type->equals('Bool')) {
    100          
    50          
42 7 100       1050 $value = $value ? \1 : \0;
43             }
44             elsif ($type->equals('ArrayRef')) {
45 8 100       2558 $value = undef if !@$value;
46             }
47             elsif ($type->equals('HashRef')) {
48 0 0       0 $value = undef if !keys %$value;
49             }
50             }
51              
52 61 100       16353 if (defined $value) {
53 30         99 $name = lower_camel_case($name);
54 30 50       1055 $result{$name} = $value if defined $value;
55             }
56              
57             }
58 8         157 return \%result;
59             }
60              
61             __PACKAGE__->meta->make_immutable;
62              
63             __END__
64              
65             =pod
66              
67             =encoding UTF-8
68              
69             =head1 NAME
70              
71             WebService::ValidSign::Object - A ValidSign object in use for the API
72              
73             =head1 VERSION
74              
75             version 0.003
76              
77             =head1 AUTHOR
78              
79             Wesley Schwengle <waterkip@cpan.org>
80              
81             =head1 COPYRIGHT AND LICENSE
82              
83             This software is Copyright (c) 2019 by Wesley Schwengle.
84              
85             This is free software, licensed under:
86              
87             The (three-clause) BSD License
88              
89             =cut