foo
[gitmo/Moose.git] / lib / Moose / Compiler / Perl5.pm
1
2 package Moose::Compiler::Perl5;
3 use Moose;
4
5 our $VERSION = '0.01';
6
7 with 'Moose::Compiler::Engine';
8
9 sub compile_class {
10     my ($self, $meta) = @_;
11     my $o = '';
12     $o .= ('package ' . $meta->name . ";\n");
13     $o .= ("\n");  
14     $o .= ("use strict;\n");    
15     $o .= ("use warnings;\n");         
16     $o .= ("\n");  
17     $o .= ("our \$VERSION = '" . $meta->version . "';\n");      
18     $o .= ("\n");  
19     $o .= ("sub new {\n");      
20     $o .= ("    my (\$class, \%params) = \@_;\n");          
21     $o .= ("    my \%proto = (\n");                  
22     foreach my $attr_name ($meta->get_attribute_list) {
23         $o .= ("        '" . $attr_name . "' => undef,\n");                          
24     }
25     $o .= ("    );\n");                      
26     $o .= ("    return bless { \%proto, \%params } => \$class;\n");              
27     $o .= ("}\n");  
28     $o .= ("\n");  
29     
30     foreach my $attr_name ($meta->get_attribute_list) {
31         my $attr = $meta->get_attribute($attr_name);        
32         $o .= ("sub " . $attr->reader    . " {" . ('') . "}\n\n")    if $attr->has_reader;                          
33         $o .= ("sub " . $attr->writer    . " {" . ('') . "}\n\n")    if $attr->has_writer;                          
34         $o .= ("sub " . $attr->accessor  . " {" . ('') . "}\n\n")  if $attr->has_accessor;                                  
35         $o .= ("sub " . $attr->predicate . " {" . ('') . "}\n\n") if $attr->has_predicate;                                          
36     }
37     
38     $o .= ("1;\n");          
39     $o .= ("\n");  
40     $o .= ("__END__\n");          
41     return $o;      
42 }
43
44 1;
45
46 __END__
47
48 =pod
49
50 =head1 NAME
51
52 Moose::Compiler::Perl5 - A Moose compiler engine for compiling to Perl 5
53
54 =head1 DESCRIPTION
55
56 =head1 METHODS
57
58 =over 4
59
60 =item B<meta>
61
62 This will return the metaclass associated with the given role.
63
64 =item B<compile_class>
65
66 =back
67
68 =head1 BUGS
69
70 All complex software has bugs lurking in it, and this module is no 
71 exception. If you find a bug please either email me, or add the bug
72 to cpan-RT.
73
74 =head1 AUTHOR
75
76 Stevan Little E<lt>stevan@iinteractive.comE<gt>
77
78 =head1 COPYRIGHT AND LICENSE
79
80 Copyright 2006 by Infinity Interactive, Inc.
81
82 L<http://www.iinteractive.com>
83
84 This library is free software; you can redistribute it and/or modify
85 it under the same terms as Perl itself. 
86
87 =cut