1 |
package Frey::ClassLoader; |
package Frey::Class::Loader; |
2 |
use Moose; |
use Moose; |
3 |
|
|
4 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
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 |
} |
} |
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 |
} |
} |
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 |
} |
} |
216 |
my ($self) = @_; |
my ($self) = @_; |
217 |
$self->sponge; |
$self->sponge; |
218 |
} |
} |
219 |
|
|
220 |
|
no Moose::Role; |
221 |
} |
} |
222 |
|
|
223 |
|
our $syntax_checked_last; |
224 |
|
|
225 |
sub new_frey_class { |
sub new_frey_class { |
226 |
my ( $self, $class, $params ) = @_; |
my ( $self, $class, $params ) = @_; |
227 |
my $instance; |
my $instance; |
228 |
|
|
229 |
|
my $path = $self->class_path( $class ); |
230 |
|
if ( $syntax_checked_last->{$class} != -C $path ) { |
231 |
|
my $syntax = `perl -Ilib -wc $path 2>&1`; |
232 |
|
warn "# syntax: $syntax"; |
233 |
|
$syntax_checked_last->{$class} = -C $class; |
234 |
|
} |
235 |
|
|
236 |
if ( $class->meta->isa('Moose::Meta::Role') ) { |
if ( $class->meta->isa('Moose::Meta::Role') ) { |
237 |
$instance = Frey->new; |
$instance = Frey->new; |
238 |
Frey::Web->meta->apply( $instance ); |
Frey::Web->meta->apply( $instance ); |
239 |
warn "new_frey_class $class role with Frey::Web"; |
warn "new_frey_class $class role with Frey::Web"; |
240 |
} else { |
} else { |
241 |
|
if ( $self->can('request_url') ) { |
242 |
|
$params->{request_url} = $self->request_url; |
243 |
|
} else { |
244 |
|
warn "## $self doesn't have request_url"; |
245 |
|
} |
246 |
$instance = $class->new( %$params ) or confess "can't $class->new".dump( %$params ); |
$instance = $class->new( %$params ) or confess "can't $class->new".dump( %$params ); |
247 |
warn "new_frey_class $class"; |
warn "new_frey_class $class"; |
248 |
} |
} |
265 |
return $instance; |
return $instance; |
266 |
} |
} |
267 |
|
|
268 |
|
__PACKAGE__->meta->make_immutable; |
269 |
|
no Moose; |
270 |
|
|
271 |
1; |
1; |