/[Frey]/trunk/lib/Frey/Class/Loader.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/Class/Loader.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/lib/Frey/ClassLoader.pm revision 586 by dpavlin, Fri Nov 28 13:27:34 2008 UTC trunk/lib/Frey/Class/Loader.pm revision 887 by dpavlin, Wed Dec 24 13:51:59 2008 UTC
# Line 1  Line 1 
1  package Frey::ClassLoader;  package Frey::Class::Loader;
2  use Moose;  use Moose;
3    
4  =head1 DESCRIPTION  =head1 DESCRIPTION
# Line 35  sub classes { Line 35  sub classes {
35                  $class =~ s{^lib/}{};                  $class =~ s{^lib/}{};
36                  $class =~ s{\.pm$}{};                  $class =~ s{\.pm$}{};
37                  $class =~ s{/}{::}g;                  $class =~ s{/}{::}g;
38                  if ( $class =~ m{Mojo} ) {                  if ( 0 && $class =~ m{Mojo} ) { # FIXME remove dead code
39                          $self->TODO( "Mojo support" );                          $self->TODO( "Mojo support" );
40                          return;                          return;
41                  }                  }
# Line 61  sub class_path { Line 61  sub class_path {
61                  my $path = $class;                  my $path = $class;
62                  $path =~ s{::}{/}g;                  $path =~ s{::}{/}g;
63                  $path .= '.pm';                  $path .= '.pm';
64                  $path = $INC{$path};                  if ( defined $INC{$path} ) {
65                  warn "# $class from INC $path";                          $path = $INC{$path};
66                  $class_path->{$class} = $path || confess "can't find path for $class";                          warn "# $class from INC $path";
67                            $class_path->{$class} = $path;
68                    } elsif ( $path =~ s{\.pm$}{} && -e "lib/${path}.pod" ) {
69                            return "lib/${path}.pod";
70                    } else {
71                            confess "can't find $class at $path";
72                    }
73          }          }
74          return $class_path->{$class};          return $class_path->{$class};
75  }  }
# Line 166  sub class_methods { Line 172  sub class_methods {
172    
173  =cut  =cut
174    
175    sub class_runnable_re { m{^as_} || m{_as_} || m{sql} }
176    
177  sub class_runnable {  sub class_runnable {
178          my ( $self, $class ) = @_;          my ( $self, $class ) = @_;
179          my @methods = grep { m{^as_} || m{_as_} } $self->class_methods( $class );          my @methods = grep { class_runnable_re } $self->class_methods( $class );
180          return @methods if wantarray;          return @methods if wantarray;
181          return \@methods;          return \@methods;
182  }  }
# Line 210  It is used by L<Frey::Run> and L<Frey::P Line 218  It is used by L<Frey::Run> and L<Frey::P
218          }          }
219  }  }
220    
221    our $syntax_checked_last;
222    
223  sub new_frey_class {  sub new_frey_class {
224          my ( $self, $class, $params ) = @_;          my ( $self, $class, $params ) = @_;
225          my $instance = $class->new( %$params );          my $instance;
226    
227            my $path = $self->class_path( $class );
228            if ( $syntax_checked_last->{$class} != -C $path ) {
229                    my $syntax = `perl -Ilib -wc $path 2>&1`;
230                    warn "# syntax: $syntax";
231                    $syntax_checked_last->{$class} = -C $class;
232            }
233    
234            if ( $class->meta->isa('Moose::Meta::Role') ) {
235                    $instance = Frey->new;
236                    Frey::Web->meta->apply( $instance );
237                    warn "new_frey_class $class role with Frey::Web";
238            } else {
239                    if ( $self->can('request_url') ) {
240                            $params->{request_url} = $self->request_url;
241                    } else {
242                            warn "## $self doesn't have request_url";
243                    }
244                    $instance = $class->new( %$params ) or confess "can't $class->new".dump( %$params );
245                    warn "new_frey_class $class";
246            }
247    
248          if ( $instance->can('data') && ! $instance->can('as_data') ) {          if ( $instance->can('data') && ! $instance->can('as_data') ) {
249                  Frey::Role::as_data->meta->apply( $instance );                  Frey::Role::as_data->meta->apply( $instance );
250                  warn "# apply as_data role to $class";                  warn "# apply as_data role to $class";

Legend:
Removed from v.586  
changed lines
  Added in v.887

  ViewVC Help
Powered by ViewVC 1.1.26