Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | # Perl module for Pastel::Attribute.pm\r |
2 | # Author: Malay < curiouser@ccmb.res.in>\r | |
3 | # Copyright Malay\r | |
4 | # You may distribute this module under the same terms as perl itself\r | |
5 | \r | |
6 | # POD documentation - main docs before the code\r | |
7 | \r | |
8 | =head1 NAME\r | |
9 | \r | |
10 | Pastel::Attribute.pm - Root attribute object of Pastel. For internal use. Don't use it directly.\r | |
11 | \r | |
12 | =head1 SYNOPSIS\r | |
13 | \r | |
14 | my $stroke_object = Pastel::BasicStroke->new();\r | |
15 | my $att = Pastel::Attribute->new(-type=>STROKE,-object=>$stroke_object);\r | |
16 | my $att1 = Pastel::Attribute->new(STROKE, $stroke_object);\r | |
17 | \r | |
18 | =head1 DESCRIPTION\r | |
19 | \r | |
20 | Pastel::Attribute wraps the key/value pair of a graphics element. It automaticslly returns the required representation (for SVG a string in the form of "key:value"), when a method is called. There are two subclasses of this class: Pastel::ShapeAttribute, and Pastel::TextAttribute.\r | |
21 | \r | |
22 | =head1 CONTACT\r | |
23 | \r | |
24 | Malay <curiouser@ccmb.ap.nic.in>\r | |
25 | \r | |
26 | =cut\r | |
27 | # Let the code begin...\r | |
28 | \r | |
29 | package Pastel::Attribute;\r | |
30 | our @ISA = qw(Pastel::Root);\r | |
31 | use Pastel::Root;\r | |
32 | use strict;\r | |
33 | \r | |
34 | =head1 CONSTRUCTOR\r | |
35 | \r | |
36 | =head2 new()\r | |
37 | \r | |
38 | Usage: $ae = Pastel::Attribute->new( -type=>"TYPE", -object=>$object);\r | |
39 | or,\r | |
40 | Pastel::Attribute->new( "TYPE", $object); \r | |
41 | \r | |
42 | Returns: A Pastel::Attribute object.\r | |
43 | \r | |
44 | Arguments: TYPE is a keyword representing the type of the $object. For a Pastel::Shape object, the valid types and the corresponding classes are: \r | |
45 | STROKE - Pastel::BasicStroke \r | |
46 | FILL - Pastel::Color \r | |
47 | STROKE-COLOR - Pastel::Color\r | |
48 | TRANSFORM - Pastel::AffineTransform\r | |
49 | =cut\r | |
50 | \r | |
51 | sub _init {\r | |
52 | my ( $self, @args ) = @_;\r | |
53 | my ($type, $object) = $self->_rearrange(['TYPE','OBJECT'], @args);\r | |
54 | if (defined($type) && defined ($object)){ \r | |
55 | $self->{key} = $type;\r | |
56 | $self->{value} = $object;\r | |
57 | return $self;\r | |
58 | }\r | |
59 | }\r | |
60 | \r | |
61 | =head2 equals()\r | |
62 | \r | |
63 | Usage: $ae = Pastel::Attribute->new("STROKE",Pastel::BasicStroke->new());\r | |
64 | $ae->equals($ae);\r | |
65 | Function: Compares two Pastel::Attribute object\r | |
66 | Returns: Returns true if they are equal or returns undef otherwise\r | |
67 | Arguments: Pastel::Attribute object;\r | |
68 | \r | |
69 | =cut\r | |
70 | \r | |
71 | sub equals {\r | |
72 | my ( $self, $object ) = @_;\r | |
73 | if ( !$object->isa("Pastel::Attribute") ) {\r | |
74 | return 0;\r | |
75 | }\r | |
76 | elsif (!( $self->to_svg() eq $object->to_svg() ))\r | |
77 | {\r | |
78 | return undef;\r | |
79 | }\r | |
80 | else {\r | |
81 | return 1;\r | |
82 | }\r | |
83 | }\r | |
84 | \r | |
85 | \r | |
86 | \r | |
87 | sub get_key {\r | |
88 | my $self = shift;\r | |
89 | return $self->{key};\r | |
90 | }\r | |
91 | \r | |
92 | =head2 get_type()\r | |
93 | \r | |
94 | Usage: \r | |
95 | Function:\r | |
96 | Example:\r | |
97 | Returns: \r | |
98 | Arguments\r | |
99 | \r | |
100 | =cut\r | |
101 | \r | |
102 | sub get_type{\r | |
103 | return $_[0]->get_key();\r | |
104 | }\r | |
105 | \r | |
106 | \r | |
107 | sub get_value {\r | |
108 | my $self = shift;\r | |
109 | return $self->{value};\r | |
110 | }\r | |
111 | \r | |
112 | sub to_svg {\r | |
113 | my $self = shift;\r | |
114 | # check whether the value stored is an object\r | |
115 | if ( $self->get_value() =~ /=HASH/ ){\r | |
116 | #print STDERR "***Iinside***\n";\r | |
117 | return $self->get_value()->to_svg(); # return just the string\r | |
118 | } else {\r | |
119 | return lc( $self->get_key() ).':'.$self->get_value();\r | |
120 | } \r | |
121 | }\r | |
122 | \r | |
123 | \r | |
124 | 1;\r |