/tags/rel-1-3-15/SWIG/Examples/perl5/shadow/example.pl
Perl | 56 lines | 30 code | 14 blank | 12 comment | 0 complexity | bb5b187e1429db0293176ca03d527145 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
1# file: example.pl
2
3# This file illustrates the low-level C++ interface
4# created by SWIG. In this case, all of our C++ classes
5# get converted into function calls.
6
7use example;
8
9# ----- Object creation -----
10
11print "Creating some objects:\n";
12$c = new example::Circle(10);
13print " Created circle $c\n";
14$s = new example::Square(10);
15print " Created square $s\n";
16
17# ----- Access a static member -----
18
19print "\nA total of $example::Shape::nshapes shapes were created\n";
20
21# ----- Member data access -----
22
23# Set the location of the object.
24# Note: methods in the base class Shape are used since
25# x and y are defined there.
26
27$c->{x} = 20;
28$c->{y} = 30;
29$s->{x} = -10;
30$s->{y} = 5;
31
32print "\nHere is their current position:\n";
33print " Circle = (",$c->{x},",", $c->{y},")\n";
34print " Square = (",$s->{x},",", $s->{y},")\n";
35
36# ----- Call some methods -----
37
38print "\nHere are some properties of the shapes:\n";
39foreach $o ($c,$s) {
40 print " $o\n";
41 print " area = ", $o->area(), "\n";
42 print " perimeter = ", $o->perimeter(), "\n";
43 }
44
45# ----- Delete everything -----
46
47print "\nGuess I'll clean up now\n";
48
49# Note: this invokes the virtual destructor
50
51$c->DESTROY();
52$s->DESTROY();
53
54print $example::Shape::nshapes," shapes remain\n";
55print "Goodbye\n";
56