/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 680 - (hide annotations)
Tue Dec 2 10:39:06 2008 UTC (15 years, 4 months ago) by dpavlin
File size: 1945 byte(s)
produce markup, make test executable
1 dpavlin 679 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 dpavlin 680 sub create_class_source_as_markup {
35 dpavlin 679 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 dpavlin 680 chmod 0755, $test_path;
65 dpavlin 679 warn "# created class $class at ", path_size($test_path);
66     system "svk add $test_path" if $self->svk_add;
67    
68 dpavlin 680 my $html
69     = qq|Created "$class" and $test_path|
70     ;
71    
72     $html = $self->editor_links( $html );
73    
74     return $html;
75 dpavlin 679 }
76    
77     =head1 DESCRIPTION
78    
79     Create Frey class based on L<Frey::Skeleton>.
80    
81     Blame this on my Smalltalk influence, because creating classes there is just
82     interface and message sends wrapped in GUI, but that makes Smalltalk books
83     much harder to read...
84    
85     On the other hand, having handy class creator within L<Frey> makes sense.
86    
87     =cut
88    
89     1;

  ViewVC Help
Powered by ViewVC 1.1.26