| 1 | |||
| 2 | package Xmldoom::Definition::Property; | ||
| 3 | |||
| 4 | use Xmldoom::Object::Property; | ||
| 5 | use Scalar::Util qw(weaken); | ||
| 6 | use strict; | ||
| 7 | |||
| 8 | sub new | ||
| 9 | { | ||
| 10 | my $class = shift; | ||
| 11 | my $args = shift; | ||
| 12 | |||
| 13 | my $parent; | ||
| 14 | my $name; | ||
| 15 | my $description; | ||
| 16 | my $hints; | ||
| 17 | my $reportable = 1; | ||
| 18 | my $searchable = 1; | ||
| 19 | my $shared = 0; | ||
| 20 | |||
| 21 | if ( ref($args) eq 'HASH' ) | ||
| 22 | { | ||
| 23 | $parent = $args->{parent}; | ||
| 24 | $name = $args->{name}; | ||
| 25 | $description = $args->{description}; | ||
| 26 | $hints = $args->{hints}; | ||
| 27 | $reportable = $args->{reportable} if defined $args->{reportable}; | ||
| 28 | $searchable = $args->{searchable} if defined $args->{searchable}; | ||
| 29 | $shared = $args->{shared} if defined $args->{shared}; | ||
| 30 | } | ||
| 31 | else | ||
| 32 | { | ||
| 33 | $parent = $args; | ||
| 34 | $name = shift; | ||
| 35 | } | ||
| 36 | |||
| 37 | my $self = { | ||
| 38 | parent => $parent, | ||
| 39 | name => $name, | ||
| 40 | description => $description || undef, | ||
| 41 | hints => $hints || { }, | ||
| 42 | reportable => $reportable || 0, | ||
| 43 | searchable => $searchable || 0, | ||
| 44 | }; | ||
| 45 | bless $self, $class; | ||
| 46 | |||
| 47 | # we have to do this before any weak references are manipulated | ||
| 48 | # because copies of weak references are strong references. | ||
| 49 | $self = Xmldoom::Threads::make_shared($self, $shared); | ||
| 50 | |||
| 51 | # weaken reference to parent | ||
| 52 | if ( defined $self->{parent} ) | ||
| 53 | { | ||
| 54 | weaken( $self->{parent} ); | ||
| 55 | } | ||
| 56 | |||
| 57 | return $self; | ||
| 58 | } | ||
| 59 | |||
| 60 | sub get_parent { return shift->{parent}; } | ||
| 61 | sub get_name { return shift->{name}; } | ||
| 62 | sub get_description { return shift->{description}; } | ||
| 63 | sub get_reportable { return shift->{reportable}; } | ||
| 64 | sub get_searchable { return shift->{searchable}; } | ||
| 65 | |||
| 66 | sub get_hint | ||
| 67 | { | ||
| 68 | my ($self, $name) = @_; | ||
| 69 | return $self->{hints}->{$name}; | ||
| 70 | } | ||
| 71 | |||
| 72 | # NOTE: you need to override for any property which forces to join | ||
| 73 | # with another table, to ensure that the table gets on the from list | ||
| 74 | # of the query. | ||
| 75 | sub get_tables | ||
| 76 | { | ||
| 77 | my $self = shift; | ||
| 78 | |||
| 79 | return [ $self->get_parent()->get_table_name() ]; | ||
| 80 | } | ||
| 81 | |||
| 82 | sub get_autoload_get_list | ||
| 83 | { | ||
| 84 | die "Abstract."; | ||
| 85 | } | ||
| 86 | |||
| 87 | sub get_autoload_set_list | ||
| 88 | { | ||
| 89 | die "Abstract."; | ||
| 90 | } | ||
| 91 | |||
| 92 | sub get_type | ||
| 93 | { | ||
| 94 | die "Abstract."; | ||
| 95 | } | ||
| 96 | |||
| 97 | sub get_data_type | ||
| 98 | { | ||
| 99 | die "Abstract."; | ||
| 100 | } | ||
| 101 | |||
| 102 | sub get | ||
| 103 | { | ||
| 104 | die "Abstract."; | ||
| 105 | } | ||
| 106 | |||
| 107 | sub set | ||
| 108 | { | ||
| 109 | die "Abstract."; | ||
| 110 | } | ||
| 111 | |||
| 112 | sub get_query_lval | ||
| 113 | { | ||
| 114 | die "Abstract."; | ||
| 115 | } | ||
| 116 | |||
| 117 | sub get_query_rval | ||
| 118 | { | ||
| 119 | die "Abstract."; | ||
| 120 | } | ||
| 121 | |||
| 122 | sub autoload | ||
| 123 | { | ||
| 124 | die "Abstract."; | ||
| 125 | } | ||
| 126 | |||
| 127 | 1; | ||
| 128 |