/[Frey]/trunk/lib/Frey/Class/Create.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/Create.pm

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

trunk/lib/Frey/ClassCreator.pm revision 680 by dpavlin, Tue Dec 2 10:39:06 2008 UTC trunk/lib/Frey/Class/Create.pm revision 1092 by dpavlin, Sun Jun 28 16:34:16 2009 UTC
# Line 1  Line 1 
1  package Frey::ClassCreator;  package Frey::Class::Create;
2  use Moose;  use Moose;
3    
4  extends 'Frey';  extends 'Frey';
# Line 13  has class => ( Line 13  has class => (
13          is => 'rw',          is => 'rw',
14          isa => 'Str',          isa => 'Str',
15          required => 1,          required => 1,
16          default => 'Frey::Skeleton',          default => 'App::Skeleton',
17  );  );
18    
19  has svk_add => (  has svk_add => (
# Line 21  has svk_add => ( Line 21  has svk_add => (
21          is => 'rw',          is => 'rw',
22          isa => 'Bool',          isa => 'Bool',
23          required => 1,          required => 1,
24          default => 0,          default => 1,
25  );  );
26    
 sub path_size {  
         my $path = shift;  
         $path .= ' ' . ( -s $path ) . ' bytes';  
         warn "# path_size: $path";  
         return $path;  
 }  
   
27  sub create_class_source_as_markup {  sub create_class_source_as_markup {
28          my ($self) = @_;          my ($self) = @_;
29    
# Line 38  sub create_class_source_as_markup { Line 31  sub create_class_source_as_markup {
31    
32          my $class_path  = $class;          my $class_path  = $class;
33          $class_path =~ s{::}{/}g;          $class_path =~ s{::}{/}g;
34          $class_path = "lib/$class.pm";          $class_path = "lib/$class_path.pm";
35    
36            my $test_path;
37    
38          my $test_path = $class;          my @c = split(m{::}, $class);
39          $test_path =~ s{::}{-};          foreach ( -1 .. $#c ) {
40          $test_path = "t/30-$test_path.t";                  my $to = $#c - $_;
41                    my $path = 't/' . join('/', @c[ 0 .. $to ] );
42                    if ( -e $path ) {
43                            my $file = join('-', @c[ $to + 1 .. $#c ] );
44                            $test_path = $path . '/' . $file . '.t';
45                            last;
46                    }
47            }
48    
49            if ( ! $test_path ) {
50                    $test_path = $class;
51                    $test_path =~ s{::}{-}g;
52                    $test_path = "t/30-$test_path.t";
53            }
54    
55          die qq|class "$class" exists |, path_size($class_path) if -e $class_path;          die qq|class "$class" exists as |, $self->path_size($class_path) if -e $class_path;
56          die qq|test for "$class" exists |, path_size($class_path) if -e $class_path;          die qq|class "$class" test exists as |, $self->path_size($test_path) if -e $test_path;
57    
58          warn "## path $class_path";          warn "## path $class_path";
59          $self->mkbasepath( $class_path );          $self->mkbasepath( $class_path );
# Line 55  sub create_class_source_as_markup { Line 63  sub create_class_source_as_markup {
63          my $code = read_file( 'lib/Frey/Skeleton.pm' );          my $code = read_file( 'lib/Frey/Skeleton.pm' );
64          $code =~ s{$skeleton}{$class}g;          $code =~ s{$skeleton}{$class}g;
65          write_file( $class_path, $code );          write_file( $class_path, $code );
66          warn "# created class $class at ", path_size($class_path);          warn "# created class $class at ", $self->path_size($class_path);
67          system "svk add $class_path" if $self->svk_add;          system "svk add $class_path" if $self->svk_add;
68    
69          $code = read_file( 't/30-frey-skeleton.t' );          $code = read_file( 't/30-frey-skeleton.t' );
70          $code =~ s{$skeleton}{$class}g;          $code =~ s{$skeleton}{$class}g;
71          write_file( $test_path, $code );          write_file( $test_path, $code );
72          chmod 0755, $test_path;          chmod 0755, $test_path;
73          warn "# created class $class at ", path_size($test_path);          warn "# created class $class at ", $self->path_size($test_path);
74          system "svk add $test_path" if $self->svk_add;          system "svk add $test_path" if $self->svk_add;
75    
76          my $html          my $html
77                  = qq|Created "$class" and $test_path|                  = qq|Created class "$class" at |
78                    . $self->path_size($class_path)
79                    . qq| and test |
80                    . $self->path_size($test_path)
81                  ;                  ;
82    
83          $html = $self->editor_links( $html );          $html = $self->html_links( $html );
84    
85          return $html;          return $html;
86  }  }

Legend:
Removed from v.680  
changed lines
  Added in v.1092

  ViewVC Help
Powered by ViewVC 1.1.26