PROPOSAL: Class::AutoCreate 
Author Message
 PROPOSAL: Class::AutoCreate

Hello,

I'd like to propose the following module that delays an object's
creation until that object is used.  So, instead of saying


You would say


Then, when you say

$a->function();

the variable is finally created and stored in $a.

The most obvious use for this module is when object creation uses a
lot of system resources, however, the way it operates introduces
another subtle (and perhaps dangerous!) application.

Assume $a is defined as above, and that we then say

$b = $a;
$a->function();
$b->function();
$c = $a;

Then $b and $a now point to different instances of Type::To::Create.
When we say $a->function() the variable $a gets set to an instance of
Type::To::Create, whereas $b still points to the original
Class::AutoCreate object.

This may seem counter-intuitive but it has a great deal of
applications.  Say for instance we have an object that we want to
associate on a one to one basis with keys of a hash.  Then, store this
object in $object.  Now, each time a hash key is created we can say:

$hash{$key} = $object;
$hash{$key}->function();

Now, every time this code is run a new object is created for each hash
value.

My questions:

* Does something else do this?
* Is the name good?

Oh, BTW, objects are instantiated on operator use too.  So,

$c = $a + 10;

will instantiate $a.

- Robby Walker
PAUSE: ROBWALKER



Mon, 12 Apr 2004 06:13:47 GMT  
 PROPOSAL: Class::AutoCreate

Quote:


>Then, when you say

>$a->function();

>the variable is finally created and stored in $a.

I think that LazyCreate or DeferCreate would be a better name; less
ambiguous and more in line with terminology used elsewhere.  (Of
course, Perl programmers have their own meaning for Lazy :-).)

--

Finger for PGP key



Tue, 13 Apr 2004 18:38:41 GMT  
 PROPOSAL: Class::AutoCreate

Quote:

> I think that LazyCreate or DeferCreate would be a better name; less
> ambiguous and more in line with terminology used elsewhere.

I chose AutoCreate because I think this module is in some respects the
complement to Class::AutoUse (which defers *loading* of a module until
it is used)

If you still think I should change the name, let me know.

- Robby



Thu, 22 Apr 2004 07:07:10 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. PROPOSAL: Class::FStructure

2. PROPOSAL: Class::Stringify

3. Proposal - Class:SimpleDBI (or something like that)

4. module proposal proposal Text::RandomQuip

5. Trouble with classes in Class::Template

6. Classes and Collections of Classes - PROBLEM

7. accessing class specific variables in inherited classes

8. Want to create class/sub-class with no package

9. ARRGH! This class has no class

10. perl Configure enhancement proposal

11. New module proposal: NetServer::Generic

12. new module proposal: I18N::Charset

 

 
Powered by phpBB® Forum Software