JSONSchema/Type/MySQL.pm

filter: Statementstmt 100% 19 / 19 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 100% 24 / 24 CC 3 SCAR 6.9
CC
3
Cov
100%
get_type_map
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« JSONSchema.pm ↑ Summary JSONSchema/Default/MySQL.pm »
1 package DBIx::Result::Convert::JSONSchema::Type::MySQL;
2  
3 =head1 NAME
4  
5 DBIx::Result::Convert::JSONSchema::Type::MySQL - Mapping of MySQL field type to JSON property type
6  
7 =head1 VERSION
8  
9 0.01
10  
11 =head1 SYNOPSIS
12  
13 use DBIx::Result::Convert::JSONSchema::Type::MySQL;
14 my $type_map = DBIx::Result::Convert::JSONSchema::Type::MySQL->get_type_map;
15  
16 =head1 DESCRIPTION
17  
18 This module defines mapping between DBIx MySQL field types to JSON schema property types.
19  
20 =cut
21  
22 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 4 our $VERSION = '0.01';
26  
27 4 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29  
30 4 Readonly my %TYPE_MAP => (
31 string => [
32 qw/ char varchar binary varbinary blob text mediumtext tinytext /,
33 qw/ date datetime timestamp time year /
34 ],
35 enum => [ qw/ enum set / ],
36 integer => [ qw/ integer smallint tinyint mediumint bigint bit / ],
37 number => [ qw/ decimal float double /, 'double precision' ],
38 object => [ qw/ json / ],
39 );
40  
41 =head2 C<get_type_map>
42  
43 Return mapping of DBIx::Class:Result field name => JSON Schema field name.
44  
45 # { decimal => 'number', time => 'string', ... }
46 my $map = DBIx::Result::Convert::Type::MySQL->get_type_map;
47  
48 =cut
49  
50 5 ▶sub get_type_map {
Subroutine get_type_map: called CC=3 SCAR=11.0
Pod documented
51 5 my ( $class ) = @_;
52  
53 5 my $mapped_fields;
54 5 foreach my $json_type ( keys %TYPE_MAP ) {
55 25 foreach my $dbix_type ( @{ $TYPE_MAP{ $json_type } } ) {
56 130 $mapped_fields->{ $dbix_type } = $json_type;
57 }
58 }
59  
60 5 return $mapped_fields;
61 }
62  
63 =head1 AUTHOR
64  
65 malishew - C<malishew@cpan.org>
66  
67 =head1 LICENSE
68  
69 This library is free software; you can redistribute it and/or modify it under
70 the same terms as Perl itself. If you would like to contribute documentation
71 or file a bug report then please raise an issue / pull request:
72  
73 https://github.com/Humanstate/p5-dbix-result-convert-jsonschema
74  
75 =cut
76  
77 4 1;
« JSONSchema.pm ↑ Summary JSONSchema/Default/MySQL.pm »