File: HasAFactory.pm

package info (click to toggle)
libclass-mixinfactory-perl 0.92-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 172 kB
  • sloc: perl: 135; makefile: 2
file content (86 lines) | stat: -rw-r--r-- 1,959 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package Class::MixinFactory::HasAFactory;

use Class::MixinFactory::NEXT;
@ISA = 'Class::MixinFactory::NEXT';

use strict;

########################################################################

use Class::MixinFactory::InsideOutAttr 'mixin_factory_ref';

sub mixin_factory {
  my $self = shift;
  my $base_class = ref($self) || $self;
  $base_class->mixin_factory_ref() or $base_class->mixin_factory_ref(
      Class::MixinFactory::Factory->new( base_class => $base_class )
  )
}

sub class {
  (shift)->mixin_factory()->class( @_ )
}

########################################################################

1;

__END__

=head1 NAME

Class::MixinFactory::HasAFactory - Delegates to a Factory

=head1 SYNOPSIS

  package My::BaseClass;
  @ISA = 'Class::MixinFactory::HasAFactory';
  sub new { ... }
  sub foo { return "Foo Bar" }

  package My::Logging;
  sub foo { warn "Calling foo"; (shift)->NEXT('foo', @_) }

  package My::UpperCase;
  sub foo { uc( (shift)->NEXT('foo', @_) ) }

  package main;
  use My::BaseClass;
  print My::BaseClass->class()->new()->foo();
  print My::BaseClass->class( 'Logging' )->new()->foo();
  print My::BaseClass->class( 'UpperCase' )->new()->foo();
  print My::BaseClass->class( 'Logging', 'UpperCase' )->new()->foo();


=head1 DESCRIPTION

A class for use by classes which want a factory method.

Inherit from this class to obtain the class() factory method, described below.

=head1 PUBLIC METHODS

=over 4

=item mixin_factory()

  BaseClass->mixin_factory() : $factory_object

Gets the associated mixin factory. Generated the first time it is needed.

=item class()

  BaseClass->class( @mixins ) : $package_name

Calls the class() method on the associated mixin factory.

=back

=head1 SEE ALSO

For a facade interface that facilitates access to this functionality, see L<Class::MixinFactory>.

For distribution, installation, support, copyright and license 
information, see L<Class::MixinFactory::ReadMe>.

=cut