/[Frey]/trunk/lib/Frey/ClassCreator.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

Contents of /trunk/lib/Frey/ClassCreator.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 679 - (show annotations)
Tue Dec 2 02:31:58 2008 UTC (15 years, 4 months ago) by dpavlin
File size: 1823 byte(s)
first draft of ClassCreator to bootstrap new classes
1 package Frey::ClassCreator;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6 with 'Frey::Path';
7 #with 'Frey::Storage';
8
9 use File::Slurp;
10
11 has class => (
12 documentation => 'Name of class to create',
13 is => 'rw',
14 isa => 'Str',
15 required => 1,
16 default => 'Frey::Skeleton',
17 );
18
19 has svk_add => (
20 documentation => 'Add created files to SVK',
21 is => 'rw',
22 isa => 'Bool',
23 required => 1,
24 default => 0,
25 );
26
27 sub path_size {
28 my $path = shift;
29 $path .= ' ' . ( -s $path ) . ' bytes';
30 warn "# path_size: $path";
31 return $path;
32 }
33
34 sub create_class_source_as_data {
35 my ($self) = @_;
36
37 my $class = $self->class;
38
39 my $class_path = $class;
40 $class_path =~ s{::}{/}g;
41 $class_path = "lib/$class.pm";
42
43 my $test_path = $class;
44 $test_path =~ s{::}{-};
45 $test_path = "t/30-$test_path.t";
46
47 die qq|class "$class" exists |, path_size($class_path) if -e $class_path;
48 die qq|test for "$class" exists |, path_size($class_path) if -e $class_path;
49
50 warn "## path $class_path";
51 $self->mkbasepath( $class_path );
52
53 my $skeleton = 'Frey::Skeleton';
54
55 my $code = read_file( 'lib/Frey/Skeleton.pm' );
56 $code =~ s{$skeleton}{$class}g;
57 write_file( $class_path, $code );
58 warn "# created class $class at ", path_size($class_path);
59 system "svk add $class_path" if $self->svk_add;
60
61 $code = read_file( 't/30-frey-skeleton.t' );
62 $code =~ s{$skeleton}{$class}g;
63 write_file( $test_path, $code );
64 warn "# created class $class at ", path_size($test_path);
65 system "svk add $test_path" if $self->svk_add;
66
67 return $code;
68 }
69
70 =head1 DESCRIPTION
71
72 Create Frey class based on L<Frey::Skeleton>.
73
74 Blame this on my Smalltalk influence, because creating classes there is just
75 interface and message sends wrapped in GUI, but that makes Smalltalk books
76 much harder to read...
77
78 On the other hand, having handy class creator within L<Frey> makes sense.
79
80 =cut
81
82 1;

  ViewVC Help
Powered by ViewVC 1.1.26