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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 768 - (hide annotations)
Tue Dec 9 20:31:30 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 1514 byte(s)
 r3627@llin (orig r746):  dpavlin | 2008-12-07 02:33:37 +0100
 Blame Newspeak for this: removed all action stuff because we don't really need it.
 
 Since we do double round trips with whole state to browser and back, it's enough just to separate second step into own package and put that into form action :-)
 

1 dpavlin 768 package Frey::Class::Refactor;
2 dpavlin 732 use Moose;
3    
4     extends 'Frey';
5     with 'Frey::Web';
6     #with 'Frey::Storage';
7    
8     use Moose::Util::TypeConstraints;
9    
10     use lib 'lib'; # :Write in vim needs it
11     use Frey::Shell::Grep;
12    
13     has from => (
14     is => 'rw',
15     isa => 'Str',
16     required => 1,
17     default => 'Frey::HTML',
18     );
19    
20     has to => (
21     is => 'rw',
22     isa => 'Str',
23     required => 1,
24     default => 'Frey::HTML::Tree',
25     );
26    
27    
28 dpavlin 768 sub as_markup {
29 dpavlin 732 my ($self) = @_;
30    
31     $self->add_css(qq|
32     span.modify {
33     display: inline;
34     backgrund: #ffc;
35     }
36     |);
37    
38     my $len = length( $self->to );
39     my $to = $self->to;
40    
41     my $change_number = 1;
42    
43     sub strip {
44     my $t = shift;
45     $t =~ s{^\s+}{}gs;
46     $t =~ s{>\s+<}{><}gs;
47     $t =~ s{\s+$}{}gs;
48     return $t;
49     }
50    
51     my $grep = Frey::Shell::Grep->new(
52     pattern => $self->from,
53     )->as_markup(
54     dd => sub {
55     my ( $patt, $path, $line, $text ) = @_;
56     $text =~ s{(\Q$patt\E)}{
57     my $nr = $change_number++;
58     strip(qq|
59     <span class="modify">
60 dpavlin 768 <input type="hidden" name="path" value="$path">
61     <input type="hidden" name="line" value="$line">
62     <input type="text" name="modification" value="$to" size=$len>
63     <input type="checkbox" name="selected" value=$nr checked>
64 dpavlin 732 </span>
65     |)
66     }egs;
67     qq|<dd><a target="editor" href="/editor+$path+$line">$line</a> <code>$text</code>|;
68     },
69     );
70    
71     $self->title( $self->from . ' => ' . $self->to );
72    
73     return qq|
74 dpavlin 768 <form class="modify" action="/Frey::Class::Refactor::Modify/as_markup" method="post">
75 dpavlin 732 $grep
76 dpavlin 768 <input type="submit" name="action" value="Modify">
77 dpavlin 732 </form>
78     |;
79     }
80    
81     1;

  ViewVC Help
Powered by ViewVC 1.1.26