package JSON::TypeInference;
use 5.008001;
use strict;
use warnings;
our $VERSION = "1.0.2";
use List::Util qw(first);
use List::UtilsBy qw(partition_by sort_by);
use JSON::TypeInference::Type::Arr
e JSON::TypeInference::Type::Boolean;
use JSON::TypeInference::Type::Maybe;
use JSON::TypeInference::Type::Null;
use JSON::TypeInference::Type::Number;
use JSON::TypeInference::Type::Object;
use JSON:
ypeInference::Type::String;
use JSON::TypeInference::Type::Union;
use JSON::TypeInference::Type::Unknown;
use constant ENTITY_TYPE_CLASSES => [
map { join '::', 'JSON::TypeInference::Type', $_ } qw
package JSON::TypeInference::Type::String;
use strict;
use warnings;
use parent qw(JSON::TypeInference::Type::Atom);
use Scalar::Util qw(looks_like_number);
sub name {
my ($class) = @_;
return '
ND__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::String - JSON string type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::String > represents JSON string type.
It is a value type, a
package JSON::TypeInference::Type::Null;
use strict;
use warnings;
use parent qw(JSON::TypeInference::Type::Atom);
sub name {
my ($class) = @_;
return 'null';
}
sub accepts {
my ($class, $data
__END__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::Null - JSON null type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Null > represents JSON null type.
It is a value type, and so
package JSON::TypeInference::Type::Array;
use strict;
use warnings;
sub new {
my ($class, $element_type) = @_;
return bless { element_type => $element_type }, $class;
}
sub name {
my ($class)
__END__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::Array - JSON array type
=head1 DESCRIPTION
JSON::TypeInference::Type::Array represents JSON array type.
It is a container type, an
package JSON::TypeInference::Type::Union;
use strict;
use warnings;
sub new {
my ($class, @types) = @_;
return bless { _types => \@types }, $class;
}
sub name {
my ($class) = @_;
return 'uni
ding utf-8
=head1 NAME
JSON::TypeInference::Type::Union - union type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Union > consists of one or more value types.
C< JSON::TypeInference::Type::Un
package JSON::TypeInference::Type::Unknown;
use strict;
use warnings;
use parent qw(JSON::TypeInference::Type::Atom);
sub name {
my ($class) = @_;
return 'unknown';
}
sub accepts {
my ($class,
JSON::TypeInference::Type::Unknown - unknown type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Unknown > is retuned if C<< JSON::TypeInference >> encountered a value that does not match any JSON
package JSON::TypeInference::Type::Atom;
use strict;
use warnings;
sub new {
my ($class) = @_;
return bless {}, $class;
}
sub signature {
my ($self) = @_;
return ref($self)->name;
}
1;
__EN
oding utf-8
=head1 NAME
JSON::TypeInference::Type::Atom - Base class for JSON value types
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Atom > is a base class for JSON value type and provides s
package JSON::TypeInference::Type::Boolean;
use strict;
use warnings;
use parent qw(JSON::TypeInference::Type::Atom);
use Types::Serialiser;
sub name {
my ($class) = @_;
return 'boolean';
}
sub
D__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::Boolean - JSON boolean type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Boolean > represents JSON boolean type.
It is a value type
package JSON::TypeInference::Type::Maybe;
use strict;
use warnings;
use List::Util qw(any);
# ArrayRef[JSON::TypeInference::Type] => Bool
sub looks_like_maybe {
my ($class, $candidate_types) = @_;
return (scalar(@$candidate_types) == 2) && any { $_->isa('JSON::TypeInference::Type::Null') } @$candidate_types;
}
sub new {
my ($class, $type) = @_;
return bless { type => $type }, $class;
}
= @_;
return 0;
}
1;
__END__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::Maybe - maybe type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Maybe > represents a possibility whether
package JSON::TypeInference::Type::Object;
use strict;
use warnings;
sub new {
my ($class, $properties) = @_;
return bless { properties => $properties }, $class;
}
sub name {
my ($class) = @_;
ND__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::Object - JSON object type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Object > represents JSON object type.
It is a container typ
package JSON::TypeInference::Type::Number;
use strict;
use warnings;
use parent qw(JSON::TypeInference::Type::Atom);
use Scalar::Util qw(looks_like_number);
sub name {
my ($class) = @_;
return '
ND__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::Number - JSON number type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Number > represents JSON number type.
It is a value type, a
encoding utf-8
=head1 NAME
JSON::TypeInference::Type - Classes of JSON types
=head1 DESCRIPTION
The implementations of JSON::TypeInference::Type represent types of JSON values.
They must implemen