~ubuntu-branches/ubuntu/jaunty/libclass-meta-perl/jaunty

« back to all changes in this revision

Viewing changes to lib/Class/Meta/Types/Perl.pm

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Krzyzaniak (eloy)
  • Date: 2006-01-03 17:29:20 UTC
  • Revision ID: james.westby@ubuntu.com-20060103172920-h94p8qrrav90bzq0
Tags: upstream-0.52
ImportĀ upstreamĀ versionĀ 0.52

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Class::Meta::Types::Perl;
 
2
 
 
3
# $Id: Perl.pm 2405 2005-12-17 03:41:09Z theory $
 
4
 
 
5
=head1 NAME
 
6
 
 
7
Class::Meta::Types::Perl - Perl data types
 
8
 
 
9
=head1 SYNOPSIS
 
10
 
 
11
  package MyApp::Thingy;
 
12
  use strict;
 
13
  use Class::Meta;
 
14
  use Class::Meta::Types::Perl;
 
15
  # OR...
 
16
  # use Class::Meta::Types::Perl 'affordance';
 
17
  # OR...
 
18
  # use Class::Meta::Types::Perl 'semi-affordance';
 
19
 
 
20
  BEGIN {
 
21
      # Create a Class::Meta object for this class.
 
22
      my $cm = Class::Meta->new( key => 'thingy' );
 
23
 
 
24
      # Add an integer attribute.
 
25
      $cm->add_attribute( name => 'my_hash',
 
26
                          type => 'hash' );
 
27
      $cm->build;
 
28
  }
 
29
 
 
30
=head1 DESCRIPTION
 
31
 
 
32
This module provides Perl data types for use with Class::Meta attributes.
 
33
Simply load it, then pass the name of one of its types to the
 
34
C<add_attribute()> method of a Class::Meta object. See
 
35
L<Class::Meta::Type|Class::Meta::Type> for more information on using and
 
36
creating data types.
 
37
 
 
38
The validation checks for Class::Meta::Types::Perl are provided by the
 
39
Class::Meta::Type's support for object type validation, since Perl data types
 
40
are understood by C<UNIVERSAL::isa()>.
 
41
 
 
42
The data types created by Class::Meta::Types::Perl are:
 
43
 
 
44
=over
 
45
 
 
46
=item scalar
 
47
 
 
48
A simple scalar value. This can be anything, and has no validation checks.
 
49
 
 
50
=item scalarref
 
51
 
 
52
A scalar reference. C<UNIVERSAL::isa()> must return 'SCALAR'.
 
53
 
 
54
=item array
 
55
 
 
56
=item arrayref
 
57
 
 
58
A array reference. C<UNIVERSAL::isa()> must return 'ARRAY'.
 
59
 
 
60
=item hash
 
61
 
 
62
=item hashref
 
63
 
 
64
A hash reference. C<UNIVERSAL::isa()> must return 'HASH'.
 
65
 
 
66
=item code
 
67
 
 
68
=item coderef
 
69
 
 
70
=item closure
 
71
 
 
72
A code reference. Also known as a closure. C<UNIVERSAL::isa()> must return
 
73
'CODE'.
 
74
 
 
75
=back
 
76
 
 
77
=cut
 
78
 
 
79
use strict;
 
80
use Class::Meta::Type;
 
81
our $VERSION = "0.52";
 
82
 
 
83
sub import {
 
84
    my ($pkg, $builder) = @_;
 
85
    $builder ||= 'default';
 
86
    return if eval "Class::Meta::Type->new('array')";
 
87
 
 
88
    Class::Meta::Type->add(
 
89
        key     => "scalar",
 
90
        name    => "Scalar",
 
91
        desc    => "Scalar",
 
92
        builder => $builder,
 
93
    );
 
94
 
 
95
    Class::Meta::Type->add(
 
96
        key     => "scalarref",
 
97
        name    => "Scalar Reference",
 
98
        desc    => "Scalar reference",
 
99
        builder => $builder,
 
100
        check   => 'SCALAR',
 
101
    );
 
102
 
 
103
    Class::Meta::Type->add(
 
104
        key     => "array",
 
105
        name    => "Array Reference",
 
106
        desc    => "Array reference",
 
107
        alias   => 'arrayref',
 
108
        builder => $builder,
 
109
        check   => 'ARRAY',
 
110
    );
 
111
 
 
112
    Class::Meta::Type->add(
 
113
        key     => "hash",
 
114
        name    => "Hash Reference",
 
115
        desc    => "Hash reference",
 
116
        alias   => 'hashref',
 
117
        builder => $builder,
 
118
        check   => 'HASH',
 
119
    );
 
120
 
 
121
    Class::Meta::Type->add(
 
122
        key     => "code",
 
123
        name    => "Code Reference",
 
124
        desc    => "Code reference",
 
125
        alias   => [qw(coderef closure)],
 
126
        builder => $builder,
 
127
        check   => 'CODE',
 
128
    );
 
129
}
 
130
 
 
131
1;
 
132
__END__
 
133
 
 
134
=head1 BUGS
 
135
 
 
136
Please send bug reports to <bug-class-meta@rt.cpan.org> or report them via the
 
137
CPAN Request Tracker at L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-Meta>.
 
138
 
 
139
=head1 AUTHOR
 
140
 
 
141
David Wheeler <david@kineticode.com>
 
142
 
 
143
=head1 SEE ALSO
 
144
 
 
145
Other classes of interest within the Class::Meta distribution include:
 
146
 
 
147
=over 4
 
148
 
 
149
=item L<Class::Meta|Class::Meta>
 
150
 
 
151
This class contains most of the documentation you need to get started with
 
152
Class::Meta.
 
153
 
 
154
=item L<Class::Meta::Type|Class::Meta::Type>
 
155
 
 
156
This class manages the creation of data types.
 
157
 
 
158
=item L<Class::Meta::Attribute|Class::Meta::Attribute>
 
159
 
 
160
This class manages Class::Meta class attributes, all of which are based on
 
161
data types.
 
162
 
 
163
=back
 
164
 
 
165
Other data type modules:
 
166
 
 
167
=over 4
 
168
 
 
169
=item L<Class::Meta::Types::String|Class::Meta::Types::String>
 
170
 
 
171
=item L<Class::Meta::Types::Boolean|Class::Meta::Types::Boolean>
 
172
 
 
173
=item L<Class::Meta::Types::Numeric|Class::Meta::Types::Numeric>
 
174
 
 
175
=back
 
176
 
 
177
=head1 COPYRIGHT AND LICENSE
 
178
 
 
179
Copyright (c) 2002-2005, David Wheeler. All Rights Reserved.
 
180
 
 
181
This module is free software; you can redistribute it and/or modify it under
 
182
the same terms as Perl itself.
 
183
 
 
184
=cut