/[cvs]/nfo/perl/libs/Class/Smart.pm
ViewVC logotype

Annotation of /nfo/perl/libs/Class/Smart.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue May 13 05:38:24 2003 UTC (21 years ago) by joko
Branch: MAIN
CVS Tags: HEAD
initial commit

1 joko 1.1 ##############################################################################
2     #
3     # Perl module: Class::Smart
4     #
5     # By Andreas Motl, andreas.motl@ilo.de
6     #
7     # $Id: XSLT.pm,v 1.6 2003/05/07 03:11:28 joko Exp $
8     #
9     # $Log: XSLT.pm,v $
10     #
11     ##############################################################################
12    
13    
14     =pod
15    
16    
17     =head1 Name
18    
19     Class::Smart - (former Class::AutoArgs)
20    
21    
22     =head1 Description
23    
24     Includes little constructor which introduces
25     passed in argument list as object attributes.
26    
27     Note: Since this list is automagically coerced to a
28     hash by perl itself, it is assumed to have
29     an even number of elements. Perl will croak
30     otherwise.
31    
32    
33     =head1 Todo
34    
35     o Handle strategy/behavior for odd number of elements inside argument list.
36     (This code is already established somewhere and gets used almost
37     everywhere throughout CPAN in various ways: see Perl: There is more
38     then one way to do it. - Please look at XML::XUpdate::XSLT::__read_arguments...)
39    
40    
41    
42     =cut
43    
44    
45     package Class::Smart;
46    
47     use strict;
48     use warnings;
49    
50     # Pseudo API: "$Class::Smart::constructor" can be set from outside to trigger initial method call(s) on fresh blessed object.
51     use vars qw( $constructor );
52    
53    
54     # ------------ mini perl object constructor ------------
55     sub new {
56    
57     # V1
58     #my $class = shift;
59    
60     # V2
61     my $invocant = shift;
62     my $class = ref($invocant) || $invocant;
63    
64     # V1
65     #return bless { @_ }, $class;
66    
67     # testing
68     #print Dumper(@_);
69     #return bless { @_ ? @_ : ('_dummy', '_dummy') }, $class;
70    
71     # V2
72     my $self = { @_ };
73     bless $self, $class;
74    
75     # Pseudo constructor mechanism - Optional: Call method on blessed reference if desired and object is capable of it.
76     # TODO: Control this (initial method call / pseudo constructor) by a designated option-flag.
77     # e.g.: $Class::Smart::AutoCall = 1; or $Class::Smart::PseudoConstructor = 1;
78     # TODO: Have a list of possible constructor names to test against...
79     # Possible solution: Have a predeclared list and/or aggregate/register all used elements throughout package lifetime.
80     $self->$constructor() if $constructor and $self->can($constructor);
81    
82     return $self;
83    
84     }
85    
86     1;
87     __END__

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed