[ Index ]

PHP Cross Reference of Unnamed Project




/se3-unattended/var/se3/unattended/install/linuxaux/opt/perl/lib/5.10.0/pod/ -> perltoot.pod (summary)

(no description)

File Size: 1836 lines (69 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

specification:: (1 method):

were:: (1 method):

Defines 1 function


Interface: specification  - X-Ref

pointer(There's not a lot to be done with a code reference beyond calling it, sothat's just what we do when we say C<&{$_[0]}>. This is just a regularfunction call, not a method call. The initial argument is the string"NAME", and any remaining arguments are whatever had been passed to themethod itself.Once we're executing inside the closure that had been created in new()   X-Ref
No description

Interface: were  - X-Ref

prototyping(function replacement with C<goto &whatever>. These all mostly makesense from the perspective of a traditional module, but as you can see,we can also use them in an object module.You can look at other object-based, struct-like overrides of corefunctions in the 5.004 release of Perl in File::stat, Net::hostent,Net::netent, Net::protoent, Net::servent, Time::gmtime, Time::localtime,User::grent, and User::pwent. These modules have a final componentthat's all lowercase, by convention reserved for compiler pragmas,because they affect the compilation and change a builtin function.They also have the type names that a C programmer would most expect.=head2 Data Members as VariablesIf you're used to C++ objects, then you're accustomed to being able toget at an object's data members as simple variables from within a method.The Alias module provides for this, as well as a good bit more, suchas the possibility of private methods that the object can call but folksoutside the class cannot.Here's an example of creating a Person using the Alias module.When you update these magical instance variables, you automaticallyupdate value fields in the hash. Convenient, eh?package Person;sub new {my $class = shift;my $self = {NAME => undef,AGE => undef,PEERS => [],};bless($self, $class)   X-Ref
No description

Functions that are not part of a class:

names(be automatically called by Perl in some way. Others that are calledimplicitly include BEGIN, END, AUTOLOAD, plus all methods used bytied objects, described in L<perltie>.In really good object-oriented programming languages, the user doesn'tcare when the destructor is called. It just happens when it's supposedto. In low-level languages without any GC at all, there's no way todepend on this happening at the right time, so the programmer mustexplicitly call the destructor to clean up memory and state, crossingtheir fingers that it's the right time to do so. Unlike C++, anobject destructor is nearly never needed in Perl, and even when it is,explicit invocation is uncalled for. In the case of our Person class,we don't need a destructor because Perl takes care of simple matterslike memory deallocation.The only situation where Perl's reference-based GC won't work iswhen there's a circularity in the data structure, such as:$this->{WHATEVER} = $this;In that case, you must delete the self-reference manually if you expectyour program not to leak memory. While admittedly error-prone, this isthe best we can do right now. Nonetheless, rest assured that when yourprogram is finished, its objects' destructors are all duly called.So you are guaranteed that an object I<eventually> gets properlydestroyed, except in the unique case of a program that never exits.If you're running Perl embedded in another application, this full GCpass happens a bit more frequently--whenever a thread shuts down.)   X-Ref
No description

call(as the same, you'll very soon be left with nothing but broken programs.First, the actual underlying calling conventions are different: methodcalls get an extra argument. Second, function calls don't do inheritance,but methods do.Method Call Resulting Function Call----------- ------------------------Person->new()   X-Ref
No description

will(it happens when you sayuse Some_Module 3.0;If you wanted to add version checking to your Person class explainedabove, just add this to Person.pm:our $VERSION = '1.1';and then in Employee.pm you can sayuse Person 1.1;And it would make sure that you have at least that version number orhigher available. This is not the same as loading in that exact versionnumber. No mechanism currently exists for concurrent installation ofmultiple versions of a module. Lamentably.=head2 Deeper UNIVERSAL detailsIt is also valid (though perhaps unwise in most cases)   X-Ref
No description

Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1