File Coverage

blib/lib/MooseX/JSONSchema/Role.pm
Criterion Covered Total %
statement 15 15 100.0
branch 1 2 50.0
condition n/a
subroutine 4 4 100.0
pod 0 2 0.0
total 20 23 86.9


line stmt bran cond sub pod time code
1             package MooseX::JSONSchema::Role;
2             our $AUTHORITY = 'cpan:GETTY';
3             # ABSTRACT: Role for classes who have JSON Schema
4             $MooseX::JSONSchema::Role::VERSION = '0.001';
5 3     3   37224 use Moose::Role;
  3         6  
  3         35  
6 3     3   19227 use JSON::MaybeXS;
  3         7  
  3         907  
7              
8             sub json_schema_data {
9 3     3 0 7 my ( $self ) = @_;
10             return {
11             map {
12 8 50       211 my $has = 'has_'.$_; $self->$has ? ( $_ => $self->$_ ) : ()
  8         284  
13 3         6 } keys %{$self->meta->json_schema_properties},
  3         15  
14             };
15             }
16              
17             sub json_schema_data_json {
18 3     3 0 388689 my ( $self, %args ) = @_;
19 3         16 my $data = $self->json_schema_data;
20 3         141 my $json = JSON::MaybeXS->new(
21             utf8 => 1,
22             canonical => 1,
23             %args,
24             );
25 3         136 return $json->encode($data);
26             }
27              
28             1;
29              
30             __END__
31              
32             =pod
33              
34             =head1 NAME
35              
36             MooseX::JSONSchema::Role - Role for classes who have JSON Schema
37              
38             =head1 VERSION
39              
40             version 0.001
41              
42             =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
43              
44             =head1 SUPPORT
45              
46             =head2 Source Code
47              
48             The code is open to the world, and available for you to hack on. Please feel free to browse it and play
49             with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
50             from your repository :)
51              
52             L<https://github.com/Getty/perl-moosex-jsonschema>
53              
54             git clone https://github.com/Getty/perl-moosex-jsonschema.git
55              
56             =head1 AUTHOR
57              
58             Torsten Raudssus <torsten@raudss.us>
59              
60             =head1 COPYRIGHT AND LICENSE
61              
62             This software is copyright (c) 2024 by Torsten Raudssus.
63              
64             This is free software; you can redistribute it and/or modify it under
65             the same terms as the Perl 5 programming language system itself.
66              
67             =cut