/[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 732 - (hide annotations)
Sat Dec 6 00:26:12 2008 UTC (15 years, 5 months ago) by dpavlin
Original Path: trunk/lib/Frey/Class/Rename.pm
File size: 2543 byte(s)
simple two step action as still non-working prototype
1 dpavlin 732 package Frey::Class::Rename;
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     sub action_order { qw/find change/ }
14     enum 'action_order' => action_order;
15    
16     has action => (
17     is => 'rw',
18     isa => 'action_order',
19     required => 1,
20     default => 'find', # FIXME first step, should be optional
21     );
22    
23     =head2 as_markup
24    
25     Simpliest possible dispatch example
26    
27     =cut
28    
29     sub as_markup {
30     my ($self) = @_;
31     my $to = $self->action;
32     $self->$to;
33     }
34    
35     # step 1 find
36    
37     has from => (
38     is => 'rw',
39     isa => 'Str',
40     required => 1,
41     default => 'Frey::HTML',
42     );
43    
44     has to => (
45     is => 'rw',
46     isa => 'Str',
47     required => 1,
48     default => 'Frey::HTML::Tree',
49     );
50    
51    
52     sub find {
53     my ($self) = @_;
54    
55     $self->add_css(qq|
56     span.modify {
57     display: inline;
58     backgrund: #ffc;
59     }
60     |);
61    
62     my $len = length( $self->to );
63     my $to = $self->to;
64    
65     my $change_number = 1;
66    
67     sub strip {
68     my $t = shift;
69     $t =~ s{^\s+}{}gs;
70     $t =~ s{>\s+<}{><}gs;
71     $t =~ s{\s+$}{}gs;
72     return $t;
73     }
74    
75     my $grep = Frey::Shell::Grep->new(
76     pattern => $self->from,
77     )->as_markup(
78     dd => sub {
79     my ( $patt, $path, $line, $text ) = @_;
80     $text =~ s{(\Q$patt\E)}{
81     my $nr = $change_number++;
82     strip(qq|
83     <span class="modify">
84     <input type="hidden" name="change_path" value="$path">
85     <input type="hidden" name="change_line" value="$line">
86     <input type="text" name="change_modification" value="$to" size=$len>
87     <input type="checkbox" name="change_selected" value=$nr checked>
88     </span>
89     |)
90     }egs;
91     qq|<dd><a target="editor" href="/editor+$path+$line">$line</a> <code>$text</code>|;
92     },
93     );
94    
95     $self->title( $self->from . ' => ' . $self->to );
96    
97     my $preserve;
98    
99     $self->step('modify');
100     $preserve .= qq|<input type="hidden" name="$_" value="| . $self->$_ . qq|">| foreach ( qw/step action_on from to/ );
101    
102     return qq|
103     <form class="modify" method="post">
104     $preserve
105     $grep
106     <input type="submit" name="action"
107     </form>
108     |;
109     }
110    
111     # step 2 modify
112    
113     has change_selected => (
114     is => 'rw',
115     isa => 'ArrayRef[Str]',
116     default => sub {},
117     );
118    
119     has change_path => (
120     is => 'rw',
121     isa => 'ArrayRef[Str]',
122     default => sub {},
123     );
124    
125     has change_line => (
126     is => 'rw',
127     isa => 'ArrayRef[Str]',
128     default => sub {},
129     );
130    
131     has change_modification => (
132     is => 'rw',
133     isa => 'ArrayRef[Str]',
134     default => sub {},
135     );
136    
137     sub modify {
138     my ($self) = @_;
139    
140     my $dump;
141     $dump->{$_} = $self->$_ foreach ( qw/change_selected change_path change_line change_modification/ );
142    
143     return $self->html_dump( $dump );
144     }
145    
146     1;

  ViewVC Help
Powered by ViewVC 1.1.26