Fixed some bugs and added tests
[gitmo/MooseX-Types.git] / lib / MooseX / TypeLibrary / Moose.pm
1 package MooseX::TypeLibrary::Moose;
2
3 =head1 NAME
4
5 MooseX::TypeLibrary::Moose - Types shipped with L<Moose>
6
7 =cut
8
9 use warnings;
10 use strict;
11
12 use MooseX::TypeLibrary;
13 use Moose::Util::TypeConstraints ();
14 use namespace::clean;
15
16 =head1 SYNOPSIS
17
18   package Foo;
19   use Moose;
20   use MooseX::TypeLibrary::Moose qw( Int Str );
21   use Carp qw( croak );
22
23   has 'name',
24     is  => 'rw',
25     isa => Str;
26
27   has 'id',
28     is  => 'rw',
29     isa => Int;
30
31   sub add {
32       my ($self, $x, $y) = @_;
33       croak 'First arg not an Int'  unless is_Int($x);
34       croak 'Second arg not an Int' unless is_Int($y);
35       return $x + $y;
36   }
37
38   1;
39
40 =head1 DESCRIPTION
41
42 This package contains a virtual library for L<MooseX::TypeLibrary> that
43 is able to export all types known to L<Moose>. See L<MooseX::TypeLibrary>
44 for general usage information.
45
46 =cut
47
48 # all available builtin types as short and long name
49 my %BuiltIn_Storage 
50   = map { ($_) x 2 } 
51     Moose::Util::TypeConstraints->list_all_builtin_type_constraints;
52
53 =head1 METHODS
54
55 =head2 type_storage
56
57 Overrides L<MooseX::TypeLibrary::Base>' C<type_storage> to provide a hash
58 reference containing all built-in L<Moose> types.
59
60 =cut
61
62 # use prepopulated builtin hash as type storage
63 sub type_storage { \%BuiltIn_Storage }
64
65 =head1 SEE ALSO
66
67 L<MooseX::TypeLibrary::Moose>,
68 L<Moose>, 
69 L<Moose::Util::TypeConstraints>
70
71 =head1 AUTHOR AND COPYRIGHT
72
73 Robert 'phaylon' Sedlacek C<E<lt>rs@474.atE<gt>>, with many thanks to
74 the C<#moose> cabal on C<irc.perl.org>.
75
76 =head1 LICENSE
77
78 This program is free software; you can redistribute it and/or modify
79 it under the same terms as perl itself.
80
81 =cut
82
83 1;