info > Class::Container

📛 NAME

Class::Container - Glues object frameworks together transparently

đŸˇī¸ VERSION

version 0.13

🚀 Quick Reference

Use CaseCommandDescription
Declare contained objects__PACKAGE__->contained_objects( ... )â›“ī¸ Register classes that are created automatically by the container
Declare valid parameters__PACKAGE__->valid_params( ... )✅ Specify accepted constructor parameters with validation
Create delayed object$self->create_delayed_object('name')âŗ Instantiate a deferred object on demand
Set delayed object parameters$self->delayed_object_params('name', ...)âš™ī¸ Adjust parameters for future delayed objects
Get delayed object class$self->delayed_object_class('name')🔍 Retrieve the class used for a delayed object
Declare decorator relationship__PACKAGE__->decorates()🎨 Set up a decorator pattern (experimental)
Show containment tree$object->show_containersđŸŒŗ Display hierarchical container relationships
Dump parameters for recreation$object->dump_parameters💾 Get a hash of parameters to reconstruct the object

📖 SYNOPSIS

        package Car;
        use Class::Container;
        @ISA = qw(Class::Container);

        __PACKAGE__->valid_params
          (
           paint  => {default => 'burgundy'},
           style  => {default => 'coupe'},
           windshield => {isa => 'Glass'},
           radio  => {isa => 'Audio::Device'},
          );

        __PACKAGE__->contained_objects
          (
           windshield => 'Glass::Shatterproof',
           wheel      => { class => 'Vehicle::Wheel',
                           delayed => 1 },
           radio      => 'Audio::MP3',
          );

        sub new {
          my $package = shift;

          # 'windshield' and 'radio' objects are created automatically by
          # SUPER::new()
          my $self = $package->SUPER::new(@_);

          $self->{right_wheel} = $self->create_delayed_object('wheel');
          ... do any more initialization here ...
          return $self;
        }

📝 DESCRIPTION

This class facilitates building frameworks of several classes that inter-operate. It was first designed and built for HTML::Mason, in which the Compiler, Lexer, Interpreter, Resolver, Component, Buffer, and several other objects must create each other transparently, passing the appropriate parameters to the right class, possibly substituting other subclasses for any of these objects.

The main features of Class::Container are:

đŸŽŦ Scenario

Suppose you've got a class called Parent, which contains an object of the class Child, which in turn contains an object of the class GrandChild. Each class creates the object that it contains. Each class also accepts a set of named parameters in its new() method. Without using Class::Container, Parent will have to know all the parameters that Child takes, and Child will have to know all the parameters that GrandChild takes. And some of the parameters accepted by Parent will really control aspects of Child or GrandChild. Likewise, some of the parameters accepted by Child will really control aspects of GrandChild. So, what happens when you decide you want to use a GrandDaughter class instead of the generic GrandChild? Parent and Child must be modified accordingly, so that any additional parameters taken by GrandDaughter can be accommodated. This is a pain - the kind of pain that object-oriented programming was supposed to shield us from.

Now, how can Class::Container help? Using Class::Container, each class (Parent, Child, and GrandChild) will declare what arguments they take, and declare their relationships to the other classes (Parent creates/contains a Child, and Child creates/contains a GrandChild). Then, when you create a Parent object, you can pass Parent->new() all the parameters for all three classes, and they will trickle down to the right places. Furthermore, Parent and Child won't have to know anything about the parameters of its contained objects. And finally, if you replace GrandChild with GrandDaughter, no changes to Parent or Child will likely be necessary.

đŸ› ī¸ METHODS

đŸ‘ī¸ SEE ALSO

Params::Validate

âœī¸ AUTHOR

Originally by Ken Williams <ken AT mathforum.org> and Dave Rolsky <autarch AT urth.org> for the HTML::Mason project. Important feedback contributed by Jonathan Swartz <swartz AT pobox.com>. Extended by Ken Williams for the AI::Categorizer project.

Currently maintained by Ken Williams.

ÂŠī¸ COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Class::Container
📛 NAME đŸˇī¸ VERSION 🚀 Quick Reference 📖 SYNOPSIS 📝 DESCRIPTION
đŸŽŦ Scenario
đŸ› ī¸ METHODS đŸ‘ī¸ SEE ALSO âœī¸ AUTHOR ÂŠī¸ COPYRIGHT

Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-16 10:11 @2600:1f28:365:80b0:7cb9:fb:26c1:e368
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!