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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 789 - (hide annotations)
Wed Dec 10 13:56:43 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 2422 byte(s)
display svk commands to rename files and commit changes
1 dpavlin 768 package Frey::Class::Refactor::Modify;
2     use Moose;
3    
4     extends 'Frey';
5     with 'Frey::Web';
6 dpavlin 772 with 'Frey::File';
7 dpavlin 768
8 dpavlin 772 has from => (
9     is => 'rw',
10     isa => 'Str',
11     required => 1,
12     );
13    
14 dpavlin 768 has selected => (
15     is => 'rw',
16     isa => 'ArrayRef[Str]',
17     default => sub {},
18     );
19    
20     has path => (
21     is => 'rw',
22     isa => 'ArrayRef[Str]',
23     default => sub {},
24     );
25    
26     has line => (
27     is => 'rw',
28     isa => 'ArrayRef[Str]',
29     default => sub {},
30     );
31    
32     has modification => (
33     is => 'rw',
34     isa => 'ArrayRef[Str]',
35     default => sub {},
36     );
37    
38     sub as_markup {
39     my ($self) = @_;
40    
41     my $dump;
42     $dump->{$_} = $self->$_ foreach ( qw/selected path line modification/ );
43 dpavlin 772 my $html = $self->html_dump( $dump );
44 dpavlin 768
45 dpavlin 772 my @content;
46     my $content_path;
47    
48     $html .= qq|<ul>|;
49    
50 dpavlin 774 my $rename;
51     my $from_path = $self->from;
52     $from_path =~ s{::}{/}g;
53    
54 dpavlin 789 my @commit;
55     my $message;
56    
57 dpavlin 772 foreach my $selected ( @{ $self->selected } ) {
58     warn "# selected ", $self->dump( $selected );
59     my $path = $self->path->[$selected] || die "no $selected path in ", $self->dump( $self->path );
60     if ( $path ne $content_path ) {
61     $content_path = $path;
62     @content = $self->read_file( $content_path );
63     warn "# got $#content lines from ", $self->path_size( $content_path );
64     }
65     my $line = $self->line->[$selected] - 1;
66     my $from = $self->from;
67     my $to = $self->modification->[$selected];
68    
69 dpavlin 774 $rename->{ $content_path } = $to if $content_path =~ m{$from_path};
70    
71 dpavlin 772 $content[ $line ] =~ s{\Q$from\E}{$to}s;
72     $self->write_file( $content_path, @content );
73 dpavlin 789 push @commit, $content_path;
74     $message ||= ref($self) . " $from -> $to";
75    
76 dpavlin 772 $html .= qq|<li>$line $from -&gt; $to <tt>| . $self->html_escape( $content[$line] ) . qq|</tt></li>|;
77     }
78    
79     $html .= qq|</ul>|;
80    
81 dpavlin 789 my $notice = qq|
82     <a target="Frey::SVK" href="/Frey::SVK/as_markup">diff</a>
83     <a target="Frey::Test::Runner" href="/Frey::Test::Runner/as_markup">test</a>
84 dpavlin 774 |;
85    
86 dpavlin 789 my $shell;
87    
88     $shell .= qq|svk commit -m "$message" | . join(' ', @commit) . qq|\n| if @commit;
89    
90     @commit = ();
91    
92 dpavlin 774 foreach my $old ( keys %$rename ) {
93     my $to = $rename->{$old};
94     $to =~ s{::}{/}g;
95     my $new = $old;
96     $new =~ s{$from_path}{$to};
97 dpavlin 789 $shell .= qq|svk mv $old $new\n|;
98     push @commit, $old;
99     push @commit, $new;
100 dpavlin 774 }
101    
102 dpavlin 789 $shell .= qq|svk commit -m "$message" | . join(' ', @commit) . qq|\n| if @commit;
103    
104     $notice .= qq|
105     <br>all in one commit and rename:
106     <pre>$shell</pre>
107     | if $shell;
108    
109     $html .= qq|
110     <div class="frey-info">
111     $notice
112     </div>
113     | if $notice;
114    
115     return $html;
116 dpavlin 768 }
117    
118     1;

  ViewVC Help
Powered by ViewVC 1.1.26