1 |
package Frey::ClassCreator; |
package Frey::Class::Create; |
2 |
use Moose; |
use Moose; |
3 |
|
|
4 |
extends 'Frey'; |
extends 'Frey'; |
5 |
with 'Frey::Web'; |
with 'Frey::Web', 'Frey::Path'; |
|
with 'Frey::Path'; |
|
|
#with 'Frey::Storage'; |
|
6 |
|
|
7 |
use File::Slurp; |
use File::Slurp; |
8 |
|
|
11 |
is => 'rw', |
is => 'rw', |
12 |
isa => 'Str', |
isa => 'Str', |
13 |
required => 1, |
required => 1, |
14 |
default => 'Frey::Skeleton', |
default => 'App::Skeleton', |
15 |
); |
); |
16 |
|
|
17 |
has svk_add => ( |
has svk_add => ( |
19 |
is => 'rw', |
is => 'rw', |
20 |
isa => 'Bool', |
isa => 'Bool', |
21 |
required => 1, |
required => 1, |
22 |
default => 0, |
default => 1, |
23 |
); |
); |
24 |
|
|
25 |
sub create_class_source_as_markup { |
sub create_class_source_as_markup { |
29 |
|
|
30 |
my $class_path = $class; |
my $class_path = $class; |
31 |
$class_path =~ s{::}{/}g; |
$class_path =~ s{::}{/}g; |
32 |
$class_path = "lib/$class.pm"; |
$class_path = "lib/$class_path.pm"; |
33 |
|
|
34 |
my $test_path = $class; |
my $test_path; |
35 |
$test_path =~ s{::}{-}; |
|
36 |
$test_path = "t/30-$test_path.t"; |
my @c = split(m{::}, $class); |
37 |
|
foreach ( -1 .. $#c ) { |
38 |
|
my $to = $#c - $_; |
39 |
|
my $path = 't/' . join('/', @c[ 0 .. $to ] ); |
40 |
|
if ( -e $path ) { |
41 |
|
my $file = join('-', @c[ $to + 1 .. $#c ] ); |
42 |
|
$test_path = $path . '/' . $file . '.t'; |
43 |
|
last; |
44 |
|
} |
45 |
|
} |
46 |
|
|
47 |
|
if ( ! $test_path ) { |
48 |
|
$test_path = $class; |
49 |
|
$test_path =~ s{::}{-}g; |
50 |
|
$test_path = "t/30-$test_path.t"; |
51 |
|
} |
52 |
|
|
53 |
die qq|class "$class" exists as |, $self->path_size($class_path) if -e $class_path; |
die qq|class "$class" exists as |, $self->path_size($class_path) if -e $class_path; |
54 |
die qq|class "$class" test exists as |, $self->path_size($test_path) if -e $test_path; |
die qq|class "$class" test exists as |, $self->path_size($test_path) if -e $test_path; |
95 |
|
|
96 |
=cut |
=cut |
97 |
|
|
98 |
|
__PACKAGE__->meta->make_immutable; |
99 |
|
no Moose; |
100 |
|
|
101 |
1; |
1; |