summaryrefslogtreecommitdiff
path: root/tools/pm/Property.pm
blob: 1f446015dc34023930d09e0d60cb34e0ab287fe5 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package Property;

use strict;
use warnings;

BEGIN {
     use Exporter   ();
     our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);

     # set the version for version checking
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
     @EXPORT      = qw(&func1 &func2 &func4);
     %EXPORT_TAGS = ( );
     # your exported package globals go here,
     # as well as any optionally exported functions
     @EXPORT_OK   = qw($Var1 %Hashit &func3);
     }
our @EXPORT_OK;

# class Property
#    {
#       string name;
#       string class;
#       string type;
#       bool readable;
#       bool writable;
#       bool construct_only;
#    }


sub new
{
  my ($def) = @_;
  my $self = {};
  bless $self;

  $def=~s/^\(//;
  $def=~s/\)$//;
  # snarf down the fields
  $$self{mark} = 0;
  $$self{name} = $1                     if ($def =~ s/^define-property (\S+)//);
  $$self{class} = $1                    if ($def =~ s/\(of-object "(\S+)"\)//);
  $$self{type} = $1                     if ($def =~ s/\(prop-type "(\S+)"\)//);
  $$self{readable} = ($1 eq "#t")       if ($def =~ s/\(readable (\S+)\)//);
  $$self{writable} = ($1 eq "#t")       if ($def =~ s/\(writable (\S+)\)//);
  $$self{construct_only} = ($1 eq "#t") if ($def =~ s/\(construct-only (\S+)\)//);

  $$self{name} =~ s/-/_/g; # change - to _

  GtkDefs::error("Unhandled property def ($def) in $$self{class}\::$$self{name}\n")
    if ($def !~ /^\s*$/);

  return $self;
}

sub dump($)
{
  my ($self) = @_;

  print "<property>\n";

  foreach (keys %$self)
  { print "  <$_ value=\"$$self{$_}\"/>\n"; }

  print "</property>\n\n";
}

sub get_construct_only($)
{
  my ($self) = @_;
  return $$self{construct_only};
}

sub get_type($)
{
  my ($self) = @_;
  return $$self{type};
}

sub get_readable($)
{
  my ($self) = @_;
  return $$self{readable};
}

sub get_writable($)
{
  my ($self) = @_;
  return $$self{writable};
}


1; # indicate proper module load.