Sponsored Content
Full Discussion: Inheritance in Perl
Top Forums Shell Programming and Scripting Inheritance in Perl Post 302624911 by birei on Tuesday 17th of April 2012 03:51:32 AM
Old 04-17-2012
Hi parthmittal2007,

shift extracts a value from the arguments of the function (@_) and assigns it to $class. The call Inventory_item->new() is the same as Inventory_item::new( "Inventory_item"), so the string will be the only argument to the function and will be assigned to the variable. After blessing it, $item will be an object with capabilities to call methods of that class.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl - variable inheritance

Hey Everyone, Does anyone know how - or if it's even possible - for a child perl script to inherit the variables of a parent perl script? In a shell script, you would use "export" for example. I am running Perl 5.8. Basically, let's say "perl1.pl" calls "perl2.pl" and I want "perl2.pl" to... (2 Replies)
Discussion started by: gsatch
2 Replies

2. Shell Programming and Scripting

Makefile: Parent - Child Inheritance and export

Hi, I have a number of Makefiles, including a couple of files that I include in Makefiles, a few scripts that are executed through Makefiles, and I have problems with environment variables that are not inherited to the scripts properly. Simplified scenario: rootdir/Makefile: all: ... (1 Reply)
Discussion started by: Shompis
1 Replies

3. AIX

WLM inheritance

Is none of you using WLM? A search gives no matches.... Anyway, I have set up a class with inheritance = yes. In the rules characteristics I have chosen a shell script as an application. This script is caught by the class, but not the child processes, which have the PID of the script as the... (6 Replies)
Discussion started by: firefox111
6 Replies

4. Programming

C++ Inheritance problem??????

Hi friends, I hope u people are ok and doing fine. I have this small problem with the derived class. I have created te base class and there is a small problem with the definition of the derived class which the compiler is pointing out, could you please help me. Here is my code #ifndef... (2 Replies)
Discussion started by: gabam
2 Replies

5. Programming

Inheritance

whats the use of inheriting with access specifier as private..? Please specify the answer with a simple example... Regards -- Madhu (5 Replies)
Discussion started by: MadhuM
5 Replies

6. Programming

Difference in multiple inheritance and multilevel inheritance: same method name ambiguity problem

Hi, In multi-level inheritance: class A { public: void fun() { cout << "A" << endl; } }; class B : public A { public: void fun() { cout << "A" << endl; } }; class C : public B { }; int main() { C c; c.fun(); // Ans: A } (1 Reply)
Discussion started by: royalibrahim
1 Replies

7. Red Hat

Ulimit Inheritance

Hi , If i start mysqld or httpd as root user which inturn starts them as "mysql" or "apache" user, will the ulimit of "root" user or ulimit of "mysql/apache" user be set for the mysql/apache processes. My understanding is that the ulimit of the user who initiates the process(root in this... (2 Replies)
Discussion started by: Hari_Ganesh
2 Replies

8. Programming

Size of derived class, in case of multiple inheritance

Why, here the size of class 'Derived' is 8 ? class Base1 { public: virtual void f() { } }; class Base2 { public: virtual void f() { } }; class Derived : public Base1, Base2 { public: virtual void f() { } }; (1 Reply)
Discussion started by: techmonk
1 Replies

9. Programming

What is wrong with below python inheritance code?

I am using python 3.4. Below is the exception I am getting- Traceback (most recent call last): File "./oop.py", line 20, in <module> y = DerivedClass("Manu") File "./oop.py", line 15, in __init__ super().__init__(self,value) TypeError: __init__() takes 2 positional arguments but... (2 Replies)
Discussion started by: Tanu
2 Replies
Template::Plugin(3)					User Contributed Perl Documentation				       Template::Plugin(3)

NAME
Template::Plugin - Base class for Template Toolkit plugins SYNOPSIS
package MyOrg::Template::Plugin::MyPlugin; use base qw( Template::Plugin ); use Template::Plugin; use MyModule; sub new { my $class = shift; my $context = shift; bless { ... }, $class; } DESCRIPTION
A "plugin" for the Template Toolkit is simply a Perl module which exists in a known package location (e.g. "Template::Plugin::*") and conforms to a regular standard, allowing it to be loaded and used automatically. The "Template::Plugin" module defines a base class from which other plugin modules can be derived. A plugin does not have to be derived from Template::Plugin but should at least conform to its object-oriented interface. It is recommended that you create plugins in your own package namespace to avoid conflict with toolkit plugins. e.g. package MyOrg::Template::Plugin::FooBar; Use the PLUGIN_BASE option to specify the namespace that you use. e.g. use Template; my $template = Template->new({ PLUGIN_BASE => 'MyOrg::Template::Plugin', }); METHODS
The following methods form the basic interface between the Template Toolkit and plugin modules. load($context) This method is called by the Template Toolkit when the plugin module is first loaded. It is called as a package method and thus implicitly receives the package name as the first parameter. A reference to the Template::Context object loading the plugin is also passed. The default behaviour for the "load()" method is to simply return the class name. The calling context then uses this class name to call the "new()" package method. package MyPlugin; sub load { # called as MyPlugin->load($context) my ($class, $context) = @_; return $class; # returns 'MyPlugin' } new($context, @params) This method is called to instantiate a new plugin object for the "USE" directive. It is called as a package method against the class name returned by load(). A reference to the Template::Context object creating the plugin is passed, along with any additional parameters specified in the "USE" directive. sub new { # called as MyPlugin->new($context) my ($class, $context, @params) = @_; bless { _CONTEXT => $context, }, $class; # returns blessed MyPlugin object } error($error) This method, inherited from the Template::Base module, is used for reporting and returning errors. It can be called as a package method to set/return the $ERROR package variable, or as an object method to set/return the object "_ERROR" member. When called with an argument, it sets the relevant variable and returns "undef." When called without an argument, it returns the value of the variable. package MyPlugin; use base 'Template::Plugin'; sub new { my ($class, $context, $dsn) = @_; return $class->error('No data source specified') unless $dsn; bless { _DSN => $dsn, }, $class; } package main; my $something = MyPlugin->new() || die MyPlugin->error(), " "; $something->do_something() || die $something->error(), " "; DEEPER MAGIC
The Template::Context object that handles the loading and use of plugins calls the new() and error() methods against the package name returned by the load() method. In pseudo-code terms looks something like this: $class = MyPlugin->load($context); # returns 'MyPlugin' $object = $class->new($context, @params) # MyPlugin->new(...) || die $class->error(); # MyPlugin->error() The load() method may alterately return a blessed reference to an object instance. In this case, new() and error() are then called as object methods against that prototype instance. package YourPlugin; sub load { my ($class, $context) = @_; bless { _CONTEXT => $context, }, $class; } sub new { my ($self, $context, @params) = @_; return $self; } In this example, we have implemented a 'Singleton' plugin. One object gets created when load() is called and this simply returns itself for each call to new(). Another implementation might require individual objects to be created for every call to new(), but with each object sharing a reference to some other object to maintain cached data, database handles, etc. This pseudo-code example demonstrates the principle. package MyServer; sub load { my ($class, $context) = @_; bless { _CONTEXT => $context, _CACHE => { }, }, $class; } sub new { my ($self, $context, @params) = @_; MyClient->new($self, @params); } sub add_to_cache { ... } sub get_from_cache { ... } package MyClient; sub new { my ($class, $server, $blah) = @_; bless { _SERVER => $server, _BLAH => $blah, }, $class; } sub get { my $self = shift; $self->{ _SERVER }->get_from_cache(@_); } sub put { my $self = shift; $self->{ _SERVER }->add_to_cache(@_); } When the plugin is loaded, a "MyServer" instance is created. The new() method is called against this object which instantiates and returns a "MyClient" object, primed to communicate with the creating "MyServer". AUTHOR
Andy Wardley <abw@wardley.org> <http://wardley.org/> COPYRIGHT
Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Template, Template::Plugins, Template::Context perl v5.12.1 2008-11-13 Template::Plugin(3)
All times are GMT -4. The time now is 06:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy