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

« back to all changes in this revision

Viewing changes to lib/Class/Meta/Types/String.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::String;
 
2
 
 
3
# $Id: String.pm 2405 2005-12-17 03:41:09Z theory $
 
4
 
 
5
=head1 NAME
 
6
 
 
7
Class::Meta::Types::String - String data types
 
8
 
 
9
=head1 SYNOPSIS
 
10
 
 
11
  package MyApp::Thingy;
 
12
  use strict;
 
13
  use Class::Meta;
 
14
  use Class::Meta::Types::String;
 
15
  # OR...
 
16
  # use Class::Meta::Types::String 'affordance';
 
17
  # OR...
 
18
  # use Class::Meta::Types::String '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 a string attribute.
 
25
      $cm->add_attribute( name => 'name',
 
26
                          type => 'string' );
 
27
      $cm->build;
 
28
  }
 
29
 
 
30
=head1 DESCRIPTION
 
31
 
 
32
This module provides a string data type for use with Class::Meta attributes.
 
33
Simply load it, then pass "string" to the C<add_attribute()> method of a
 
34
Class::Meta object to create an attribute of the string data type. See
 
35
L<Class::Meta::Type|Class::Meta::Type> for more information on using and
 
36
creating data types.
 
37
 
 
38
=cut
 
39
 
 
40
use strict;
 
41
use Class::Meta::Type;
 
42
our $VERSION = "0.52";
 
43
 
 
44
sub import {
 
45
    my ($pkg, $builder) = @_;
 
46
    $builder ||= 'default';
 
47
    return if eval "Class::Meta::Type->new('string')";
 
48
 
 
49
    Class::Meta::Type->add(
 
50
        key     => "string",
 
51
        name    => "String",
 
52
        desc    => "String",
 
53
        builder => $builder,
 
54
        check   => sub {
 
55
            return unless defined $_[0] && ref $_[0];
 
56
            $_[2]->class->handle_error("Value '$_[0]' is not a valid string");
 
57
        }
 
58
    );
 
59
}
 
60
 
 
61
1;
 
62
__END__
 
63
 
 
64
=head1 BUGS
 
65
 
 
66
Please send bug reports to <bug-class-meta@rt.cpan.org> or report them via the
 
67
CPAN Request Tracker at L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-Meta>.
 
68
 
 
69
=head1 AUTHOR
 
70
 
 
71
David Wheeler <david@kineticode.com>
 
72
 
 
73
=head1 SEE ALSO
 
74
 
 
75
Other classes of interest within the Class::Meta distribution include:
 
76
 
 
77
=over 4
 
78
 
 
79
=item L<Class::Meta|Class::Meta>
 
80
 
 
81
This class contains most of the documentation you need to get started with
 
82
Class::Meta.
 
83
 
 
84
=item L<Class::Meta::Type|Class::Meta::Type>
 
85
 
 
86
This class manages the creation of data types.
 
87
 
 
88
=item L<Class::Meta::Attribute|Class::Meta::Attribute>
 
89
 
 
90
This class manages Class::Meta class attributes, all of which are based on
 
91
data types.
 
92
 
 
93
=back
 
94
 
 
95
Other data type modules:
 
96
 
 
97
=over 4
 
98
 
 
99
=item L<Class::Meta::Types::Perl|Class::Meta::Types::Perl>
 
100
 
 
101
=item L<Class::Meta::Types::Boolean|Class::Meta::Types::Boolean>
 
102
 
 
103
=item L<Class::Meta::Types::Numeric|Class::Meta::Types::Numeric>
 
104
 
 
105
=back
 
106
 
 
107
=head1 COPYRIGHT AND LICENSE
 
108
 
 
109
Copyright (c) 2002-2005, David Wheeler. All Rights Reserved.
 
110
 
 
111
This module is free software; you can redistribute it and/or modify it under
 
112
the same terms as Perl itself.
 
113
 
 
114
=cut