blib/lib/Kwiki/RenamePage.pm

filter: Statementstmt 37.9% 22 / 58 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod n/a totaltotal 38.4% 30 / 78 CC 7 SCAR 32.2
CC
7
Cov
32%
rename_page
56.0
register
2.0
BEGIN
1.3
CRAP 25.1
↑ Summary
1 package Kwiki::RenamePage;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Kwiki::RenamePage - Better Names for Misnamed Kwiki Pages
9  
10 =head1 VERSION
11  
12 Version 0.01
13  
14 =cut
15  
16 our $VERSION = '0.02';
17  
18 =head1 SYNOPSIS
19  
20 Moves content of OldPage to NewName, replacing it with the message, "This page has moved to NewName." Text in other pages which could have been a link to OldPage is changed to link to NewName, but with the old text left parenthesized as, "(Old name: OldPage)".
21  
22 =cut
23  
24 2 ▶use Kwiki::Plugin '-Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use mixin 'Kwiki::NewPage';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use mixin 'Kwiki::Installer';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 =head1 class_id
29  
30 Unmodifiable Class id accessor
31  
32 =cut
33  
34 const class_id => 'rename_page';
35  
36 =head1 cgi_class
37  
38 Unmodifiable Class class accessor
39  
40 =cut
41  
42 const cgi_class => 'Kwiki::RenamePage::CGI';
43  
44 =head1 screen_template
45  
46 unmodifiable screen_template accessor
47  
48 =cut
49  
50 const screen_template => 'rename_page_content.html';
51  
52 =head1 old_page_name
53  
54 Modifiable old_page_name accessor
55  
56 =cut
57  
58 field 'old_page_name';
59  
60 =head1 old_page_content
61  
62 Modifiable old_page_content accessor
63  
64 =cut
65  
66 field 'old_page_content';
67  
68 # field 'page_time';
69  
70 =head1 METHODS
71  
72 =over 8
73  
74 =item B<register>
75  
76 Plug the plugin in.
77  
78 =cut
79  
80 0 ▶sub register {
Subroutine register: not called CC=1 SCAR=6.9
81 0 my $registry = shift;
82 0 $registry->add( action => 'rename_page' );
83 0 $registry->add( toolbar => 'rename_page_button',
84 template => 'rename_page_button.html' );
85 }
86  
87 =item B<rename_page>
88  
89 Rename the page.
90  
91 =cut
92  
93 0 ▶sub rename_page {
Subroutine rename_page: not called CC=7 SCAR=40.3
94 0 my $page = $self->pages->current;
95 0 my $old_name = $self->cgi->old_page_name;
96 0 my $new_name = $self->cgi->new_page_name;
97 0 $self->old_page_name( $self->cgi->page_name );
98 0 my $error_msg = '';
99 0 my $page_uri;
100 0 ▶ if ( $self->cgi->button ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cgi->button) 0 0 0
101 0 ▶ $error_msg = $self->check_page_name or do {
Branch: 1 branch
BranchTrueFalseTotal
$error_msg = $self->check_page_name or do { my $old_page = $self->pages->new_from_name($old_name); my $new_page = $self->pages->new_from_name($new_name); return $self->redirect($new_page->uri) unless $new_page->is_writable; my $current = $self->pages->current($old_page); my $yanked_content = $current->content; $current->content("This page has moved to $new_name."); if ($current->modified_time != $self->cgi->page_time) { return "action=edit_contention;page_name=$current->uri"; } ; $current->update->store; my $link = qr/$old_name/; foreach my $page ($self->pages->all) { my $content = $page->content; $content =~ s/$old_name/$new_name (Old name: $old_name)/g; $page->content($content); $page->update->store; } ; $current = $self->pages->current($new_page); $current->content($yanked_content); $current->update->store; return $self->redirect($current->uri) } 0 0 0
102 0 my $old_page = $self->pages->new_from_name( $old_name );
103 0 my $new_page = $self->pages->new_from_name( $new_name );
104 0 ▶ return $self->redirect( $new_page->uri )
Branch: 1 branch
BranchTrueFalseTotal
unless $new_page->is_writable 0 0 0
105 unless $new_page->is_writable;
106 0 my $current = $self->pages->current($old_page);
107 0 my $yanked_content = $current->content;
108 0 $current->content("This page has moved to $new_name.");
109 0 ▶ if ( $current->modified_time != $self->cgi->page_time )
Branch: 1 branch
BranchTrueFalseTotal
if ($current->modified_time != $self->cgi->page_time) 0 0 0
110 {
111 0 return("action=edit_contention;page_name=$current->uri");
112 }
113 0 $current->update->store;
114 0 my $link = qr/$old_name/;
115 0 for my $page ( $self->pages->all )
116 {
117 # my $current = $self->pages->current($page);
118 0 my $content = $page->content;
119 0 $content =~ s/$old_name/$new_name (Old name: $old_name)/g;
120 0 $page->content($content);
121 0 $page->update->store;
122 }
123 0 $current = $self->pages->current($new_page);
124 0 $current->content($yanked_content);
125 0 $current->update->store;
126 0 return $self->redirect($current->uri);
127 }
128 }
129 0 ▶ return $self->render_screen( error_msg => $error_msg ) if $error_msg;
Branch: 1 branch
BranchTrueFalseTotal
if $error_msg 0 0 0
130 0 return $self->render_screen( old_page_name => $self->old_page_name,
131 page_time => $page->modified_time);
132 }
133  
134 package Kwiki::RenamePage::CGI;
135 0 ▶use Kwiki::CGI '-base';
Subroutine BEGIN: called CC=1 SCAR=2.6
136  
137 cgi 'new_page_name';
138 cgi 'old_page_name';
139 cgi 'page_name';
140 cgi 'page_time';
141  
142 1;
143  
144 package Kwiki::RenamePage;
145  
146 =back
147  
148 =head1 AUTHOR
149  
150 Dr Bean, C<< <drbean, then an at sign, cpan, a dot, and finally org> >>
151  
152 =head1 BUGS
153  
154 Please report any bugs or feature requests to
155 C<bug-kwiki-renamepage at rt.cpan.org>, or through the web interface at
156 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Kwiki::RenamePage>.
157 I will be notified, and then you'll automatically be notified of progress on
158 your bug as I make changes.
159  
160 =head1 SUPPORT
161  
162 You can find documentation for this module with the perldoc command.
163  
164 perldoc Kwiki::RenamePage
165  
166 You can also look for information at:
167  
168 =over 4
169  
170 =item * AnnoCPAN: Annotated CPAN documentation
171  
172 L<http://annocpan.org/dist/Kwiki::RenamePage>
173  
174 =item * CPAN Ratings
175  
176 L<http://cpanratings.perl.org/d/Kwiki::RenamePage>
177  
178 =item * RT: CPAN's request tracker
179  
180 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Kwiki::RenamePage>
181  
182 =item * Search CPAN
183  
184 L<http://search.cpan.org/dist/Kwiki::RenamePage>
185  
186 =back
187  
188 =head1 ACKNOWLEDGEMENTS
189  
190 =head1 COPYRIGHT & LICENSE
191  
192 Copyright 2006 Dr Bean, all rights reserved.
193  
194 This program is free software; you can redistribute it and/or modify it
195 under the same terms as Perl itself.
196  
197 =cut
198  
199 1; # End of Kwiki::RenamePage
200  
201 __DATA__
↑ Summary