File: Property.pm

package info (click to toggle)
liboptimade-propertydefinitions-perl 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,996 kB
  • sloc: sh: 348; perl: 184; python: 38; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,637 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package OPTIMADE::PropertyDefinitions::Property;

# ABSTRACT: OPTIMADE Property
our $VERSION = '0.1.0'; # VERSION

use strict;
use warnings;

use List::Util qw( any );
use OPTIMADE::PropertyDefinitions::Property::Nested;

sub new
{
    my( $class, $parent, $name ) = @_;
    return bless { parent => $parent, name => $name }, $class;
}

sub name() { $_[0]->{name} }
sub parent() { $_[0]->{parent} }

sub property($)
{
    my( $self, $property ) = @_;

    if( !exists $self->raw->{properties} ||
        !exists $self->raw->{properties}{$property} ) {
        die "no such property '$property'\n";
    }

    return OPTIMADE::PropertyDefinitions::Property::Nested->new( $self, $property );
}

sub properties()
{
    my( $self ) = @_;
    return my @empty unless exists $self->raw->{properties};
    return map { OPTIMADE::PropertyDefinitions::Property::Nested->new( $self, $_ ) }
               sort keys %{$self->raw->{properties}};
}

sub description() { $_[0]->raw->{description} }
sub format() { $_[0]->raw->{format} }
sub optimade_type() { $_[0]->raw->{'x-optimade-type'} }
sub query_support() { $_[0]->parent->raw->{'query-support'} }
sub required() { exists $_[0]->raw->{required} ? @{$_[0]->raw->{required}} : my @empty }
sub response_level() { $_[0]->parent->raw->{'response-level'} }
sub sortable() { $_[0]->parent->raw->{sortable} }
sub support() { $_[0]->parent->raw->{support} }
sub type() { @{$_[0]->raw->{type}} }
sub unit() { $_[0]->raw->{'x-optimade-unit'} }
sub version() { $_[0]->raw->{version} }

sub is_nullable() { any { $_ eq 'null' } $_[0]->type }

sub raw() { $_[0]->parent->raw->{properties}{$_[0]->name} }

1;