/[Frey]/branches/no-pager/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

Contents of /branches/no-pager/lib/Frey/Class/Refactor.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 746 - (show annotations)
Sun Dec 7 01:33:37 2008 UTC (15 years, 4 months ago) by dpavlin
File size: 1514 byte(s)
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 package Frey::Class::Refactor;
2 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 sub as_markup {
29 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 <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 </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 <form class="modify" action="/Frey::Class::Refactor::Modify/as_markup" method="post">
75 $grep
76 <input type="submit" name="action" value="Modify">
77 </form>
78 |;
79 }
80
81 1;

  ViewVC Help
Powered by ViewVC 1.1.26