Changeset 82
- Timestamp:
- 09/12/06 09:09:59 (2 years ago)
- Files:
-
- trunk/lib/PrlMnks/DBI.pm (modified) (1 diff)
- trunk/lib/PrlMnks/Plugin.pm (modified) (3 diffs)
- trunk/lib/PrlMnks/Plugin/List.pm (modified) (9 diffs)
- trunk/t/plugin/base/if-modified-since.t (modified) (1 diff)
- trunk/t/plugin/default/default.t (modified) (1 diff)
- trunk/t/plugin/list/list.t (added)
- trunk/t/plugin/list/url_to_args.t (modified) (9 diffs)
- trunk/t/plugin/rss/rss.t (modified) (2 diffs)
- trunk/t/setup_testing_environment.pl (modified) (3 diffs)
- trunk/templates/list/list.mason (modified) (2 diffs)
- trunk/templates/list/list_options.mason (modified) (1 diff)
- trunk/templates/top.mason (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/PrlMnks/DBI.pm
r81 r82 36 36 my $class = shift; 37 37 my $dbh = shift; 38 my @sql = (); 38 39 39 my $sql = << "SQL_END"; 40 create table nodes ( 41 node_id integer primary key, 42 title text, 43 created text, 44 updated text, 45 year integer, 46 month integer, 47 type_id integer, 48 type_name text, 49 author_id integer, 50 author_name text, 51 content text, 52 root_node_id integer, 53 parent_node_id integer 54 ); 55 SQL_END 40 push @sql, 41 "create table nodes ( " 42 . " node_id integer primary key, " 43 . " title text, " 44 . " created text, " 45 . " updated text, " 46 . " year integer, " 47 . " month integer, " 48 . " type_id integer, " 49 . " type_name text, " 50 . " author_id integer, " 51 . " author_name text, " 52 . " content text, " 53 . " root_node_id integer, " 54 . " parent_node_id integer " 55 . "); "; 56 56 57 $dbh->do($sql) || die $dbh->errstr; 57 push @sql, # 58 "CREATE INDEX nodes_type_index" . # 59 " ON nodes( type_name );"; 60 61 push @sql, # 62 "CREATE INDEX nodes_type_year_index" . # 63 " ON nodes( type_name, year );"; 64 65 push @sql, # 66 "CREATE INDEX nodes_type_year_month_index" 67 . " ON nodes( type_name, year, month );"; 68 69 for (@sql) { 70 $dbh->do($_) || die $dbh->errstr; 71 } 58 72 } 59 73 trunk/lib/PrlMnks/Plugin.pm
r81 r82 180 180 my %SUFFIX_TO_MIME_TYPE = ( 181 181 '' => 'text/html', 182 'css' => 'text/css', 183 'gif' => 'image/gif', 184 'html' => 'text/html', 185 'ico' => 'image/x-icon', 186 'jpg' => 'image/jpeg', 187 'json' => 'application/json', 188 'png' => 'image/png', 182 189 'txt' => 'text/plain', 183 190 'xml' => 'text/xml', 184 'ico' => 'image/x-icon',185 'png' => 'image/png',186 'jpg' => 'image/jpeg',187 'gif' => 'image/gif',188 'html' => 'text/html',189 'json' => 'application/json',190 191 ); 191 192 … … 196 197 # If the file is not there then 404 197 198 return $self->error_404 unless -e $file; 198 199 # use Time::HiRes 'time';200 # warn "1 - " . time;201 199 202 200 # Has the file changed? … … 211 209 } 212 210 213 warn "2 - " . time;214 215 211 # content type based on file suffix 216 212 $file =~ m{ \. ([^\./]+) \z }xms; trunk/lib/PrlMnks/Plugin/List.pm
r81 r82 10 10 =head1 URL 11 11 12 /list/ node_type/year/month12 /list/type_name/year/month 13 13 14 all can be empty. If no C< node_type> then a list of categories is shown. If14 all can be empty. If no C<type_name> then a list of categories is shown. If 15 15 there is no year or month specified then the current year and month are used. 16 16 17 17 =cut 18 19 sub add_node { 20 my $self = shift; 21 my $node = shift; 22 my $node_data = $node->as_hashref; 23 my @to_delete = (); 24 25 push @to_delete, # 26 $self->list_file( @$node_data{qw( type_name )} ), 27 $self->list_file( @$node_data{qw( type_name year )} ), 28 $self->list_file( @$node_data{qw( type_name year month )} ); 29 30 foreach my $file (@to_delete) { 31 next unless -e $file; 32 unlink $file; 33 } 34 35 return 1; 36 } 37 38 sub update_node { die } 39 sub delete_node { die } 40 41 sub list_file { 42 my $self = shift; 43 return $self->shared( 'list', grep { $_ } @_ ) . '.html'; 44 } 18 45 19 46 sub start_of_url { '/list/' } … … 27 54 # If any of the values are undef then the url is bad - 404 it. 28 55 return $self->error_404 if grep { !defined $_ } values %$args; 56 57 # work out what the cached file name should be. 58 my $cache_file = $self->list_file( @$args{qw(type_name year month)} ); 59 60 # if the content is cached then use that. 61 return $self->send_file($cache_file) if -e $cache_file; 29 62 30 63 # Set the vars to args. … … 40 73 41 74 # If this is the homepage then use the homepage template. 42 return $self->send_template('/list/list.mason'); 75 return $self->send_template( '/list/list.mason', 76 { cache_to => $cache_file } ); 43 77 } 44 78 … … 57 91 58 92 # get the details from the url. 59 my ( $undef, $list, $ node_type, $year, $month ) = split /\//, $url;93 my ( $undef, $list, $type_name, $year, $month ) = split /\//, $url; 60 94 61 # Get the node_type. If it is not allowed then set it to ''.62 $ node_type ||= '';63 $ node_type = undef64 unless $ node_type eq ''65 || PrlMnks::Type->get($ node_type);95 # Get the type_name. If it is not allowed then set it to ''. 96 $type_name ||= ''; 97 $type_name = undef 98 unless $type_name eq '' 99 || PrlMnks::Type->get($type_name); 66 100 67 101 for ( $year, $month ) { … … 75 109 && ( $month < 1 || $month > 12 ); 76 110 77 return { node_type => $node_type, year => $year, month => $month };111 return { type_name => $type_name, year => $year, month => $month }; 78 112 } 79 113 … … 93 127 my @sql_args = (); 94 128 95 if ( !$args->{ node_type} ) {129 if ( !$args->{type_name} ) { 96 130 $sql = "select distinct type_name" # 97 131 . " from nodes" # … … 104 138 . " where type_name = ?" 105 139 . " order by year"; 106 @sql_args = ( $args->{ node_type} );140 @sql_args = ( $args->{type_name} ); 107 141 } 108 142 elsif ( !$args->{month} ) { … … 111 145 . " where type_name = ? and year = ?" 112 146 . " order by month"; 113 @sql_args = ( $args->{ node_type}, $args->{year} );147 @sql_args = ( $args->{type_name}, $args->{year} ); 114 148 } 115 149 … … 137 171 . " order by node_id"; 138 172 139 my @sql_args = @$args{qw( node_type year month )};173 my @sql_args = @$args{qw( type_name year month )}; 140 174 141 175 my @nodes = (); trunk/t/plugin/base/if-modified-since.t
r73 r82 48 48 49 49 # touch the file and check that we get a 200 again. 50 sleep 2; # so that the change is not in the same second as above. 50 51 `echo 'bob' >> $file`; 51 52 $mech->get_ok( $url, "get '$url'" ); trunk/t/plugin/default/default.t
r50 r82 23 23 # Get a static file - check content-type 24 24 25 my %tests = ( '/robots.txt' => 'text/plain', '/' => 'text/html' ); 25 my %tests = ( 26 '/' => 'text/html', 27 '/css/default.css' => 'text/css', 28 '/robots.txt' => 'text/plain', 29 ); 26 30 27 31 while ( my ( $url, $ct ) = each %tests ) { trunk/t/plugin/list/url_to_args.t
r81 r82 11 11 use PrlMnks::Plugin::List; 12 12 13 # 0 1 2 3 4 5 6 7 814 # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)15 16 # my @date = localtime;17 # my $year = $date[5] + 1900;18 # my $month = $date[4] + 1;19 #20 # diag "year: '$year', month: '$month'.";21 22 13 my %tests = ( 23 14 24 15 "/list/" => { 25 node_type => "",16 type_name => "", 26 17 year => "", 27 18 month => "", … … 29 20 30 21 "/list/perlmeditation" => { 31 node_type => "perlmeditation",22 type_name => "perlmeditation", 32 23 year => "", 33 24 month => "", … … 35 26 36 27 "/list/perlmeditation/2005" => { 37 node_type => "perlmeditation",28 type_name => "perlmeditation", 38 29 year => 2005, 39 30 month => "", … … 41 32 42 33 "/list/perlmeditation/2005/10" => { 43 node_type => "perlmeditation",34 type_name => "perlmeditation", 44 35 year => 2005, 45 36 month => 10, … … 47 38 48 39 "/list/bogus/2005/10" => { 49 node_type => undef,40 type_name => undef, 50 41 year => 2005, 51 42 month => 10, … … 53 44 54 45 "/list/perlmeditation/bogus/10" => { 55 node_type => "perlmeditation",46 type_name => "perlmeditation", 56 47 year => undef, 57 48 month => 10, … … 59 50 60 51 "/list/perlmeditation/2005/bogus" => { 61 node_type => "perlmeditation",52 type_name => "perlmeditation", 62 53 year => 2005, 63 54 month => undef, … … 65 56 66 57 "/list/perlmeditation/2005/0" => { 67 node_type => "perlmeditation",58 type_name => "perlmeditation", 68 59 year => 2005, 69 60 month => undef, … … 71 62 72 63 "/list/perlmeditation/2005/13" => { 73 node_type => "perlmeditation",64 type_name => "perlmeditation", 74 65 year => 2005, 75 66 month => undef, trunk/t/plugin/rss/rss.t
r72 r82 19 19 } 20 20 21 # Add a load of nodes to the database: 22 # 508076 Scrabble word arrangements with blank tiles 23 # 508076 508081 Re: Scrabble word arrangements with blank tiles 24 # 508076 508170 Re: Scrabble word arrangements with blank tiles 25 # 508170 508234 Re^2: Scrabble word arrangements with blank tiles 26 # 508234 508363 Re^3: Scrabble word arrangements with blank tiles 27 # 508076 508208 Re: Scrabble word arrangements with blank tiles 28 # 508208 508216 Re^2: Scrabble word arrangements with blank tiles 29 # 508208 508218 Re^2: Scrabble word arrangements with blank tiles 30 # 508218 508223 Re^3: Scrabble word arrangements with blank tiles 31 # 508208 508221 Re^2: Scrabble word arrangements with blank tiles 32 # 508221 508245 Re^3: Scrabble word arrangements with blank tiles 33 # 508076 508299 Re: Scrabble word arrangements with blank tiles 34 # 508299 508411 Re^2: Scrabble word arrangements with blank tiles 35 # 508299 509065 Re^2: Scrabble word arrangements with blank tiles 36 # 508076 508350 Re: Scrabble word arrangements with blank tiles 37 # 508076 509993 Re: Scrabble word arrangements with blank tiles 38 my @ids = ( 39 40 # Scrabble thread nodes 41 508076, 508081, 508170, 508208, 508216, 508218, 42 508221, 508223, 508234, 508245, 508299, 508350, 43 508363, 508411, 509065, 509993, 44 45 # Anonymous monk and perlquestions. 46 961, 432878, 115, 47 ); 48 49 # Foreach id create a node and then run the plugin on it. 50 my %nodes = (); 51 foreach my $id (@ids) { 52 my $node = 53 PrlMnks::Node->new( xml => scalar slurp "test_data/flat/$id-flat.xml" ); 54 $node->parse_xml && $node->save_to_db; 55 ok $p->add_node($node), "added node '$id'"; 56 $nodes{$id} = $node; 57 } 21 my $nodes = setup_scrabble_data( plugin => $p ); 58 22 59 23 # Fetch RSS for 508208, 508218, 508223. Check that the RSS is created and … … 70 34 # Check that adding nodes leads to the parents being deleted - but not the 71 35 # children. 72 ok $p->add_node( $nodes {508218} ), "added node '508218'";36 ok $p->add_node( $nodes->{508218} ), "added node '508218'"; 73 37 ok !-e $paths{508208}, "not found '$paths{508208}'"; 74 38 ok !-e $paths{508218}, "not found '$paths{508218}'"; trunk/t/setup_testing_environment.pl
r65 r82 4 4 use Test::WWW::Mechanize; 5 5 use Carp; 6 use Perl6::Slurp; 6 7 7 8 # NOTE - do not 'use' any PrlMnks modules here as the ENV variables must be … … 9 10 10 11 # Set the environment variables correctly 11 $ENV{PRLMNKS_SHARED} = ''; 12 $ENV{PRLMNKS_BASE} = 't/base'; 13 $ENV{PRLMNKS_CURRENT} = '.'; 12 BEGIN { 13 $ENV{PRLMNKS_SHARED} = ''; 14 $ENV{PRLMNKS_BASE} = 't/base'; 15 $ENV{PRLMNKS_CURRENT} = '.'; 16 } 14 17 15 18 eval("use PrlMnks; 1;") || die $@; … … 42 45 } 43 46 47 sub setup_scrabble_data { 48 my %args = @_; 49 my $plugin = $args{plugin}; 50 51 # Add a load of nodes to the database: 52 # 508076 Scrabble word arrangements with blank tiles 53 # 508076 508081 Re: Scrabble word arrangements with blank tiles 54 # 508076 508170 Re: Scrabble word arrangements with blank tiles 55 # 508170 508234 Re^2: Scrabble word arrangements with blank tiles 56 # 508234 508363 Re^3: Scrabble word arrangements with blank tiles 57 # 508076 508208 Re: Scrabble word arrangements with blank tiles 58 # 508208 508216 Re^2: Scrabble word arrangements with blank tiles 59 # 508208 508218 Re^2: Scrabble word arrangements with blank tiles 60 # 508218 508223 Re^3: Scrabble word arrangements with blank tiles 61 # 508208 508221 Re^2: Scrabble word arrangements with blank tiles 62 # 508221 508245 Re^3: Scrabble word arrangements with blank tiles 63 # 508076 508299 Re: Scrabble word arrangements with blank tiles 64 # 508299 508411 Re^2: Scrabble word arrangements with blank tiles 65 # 508299 509065 Re^2: Scrabble word arrangements with blank tiles 66 # 508076 508350 Re: Scrabble word arrangements with blank tiles 67 # 508076 509993 Re: Scrabble word arrangements with blank tiles 68 my @ids = ( 69 70 # Scrabble thread nodes 71 508076, 508081, 508170, 508208, 508216, 508218, 72 508221, 508223, 508234, 508245, 508299, 508350, 73 508363, 508411, 509065, 509993, 74 75 # Anonymous monk and perlquestions. 76 961, 432878, 115, 77 ); 78 79 # Foreach id create a node and then run the plugin on it. 80 my %nodes = (); 81 foreach my $id (@ids) { 82 my $node = 83 PrlMnks::Node->new( 84 xml => scalar slurp "test_data/flat/$id-flat.xml" ); 85 $node->parse_xml && $node->save_to_db; 86 ok $plugin->add_node($node), "added node '$id'"; 87 $nodes{$id} = $node; 88 } 89 90 return \%nodes; 91 92 } 93 44 94 1; 45 95 trunk/templates/list/list.mason
r81 r82 9 9 10 10 <%args> 11 $ node_type11 $type_name 12 12 $year 13 13 $month … … 26 26 27 27 <%perl> 28 if ( ! $ node_type ) {29 $m->comp( 'list_options.mason', what => ' node_type' );28 if ( ! $type_name ) { 29 $m->comp( 'list_options.mason', what => 'type_name' ); 30 30 } elsif ( ! $year ) { 31 31 $m->comp( 'list_options.mason', what => 'year' ); trunk/templates/list/list_options.mason
r81 r82 13 13 14 14 my $base_url = '/list'; 15 foreach my $key ( qw( node_type year month ) ) {15 foreach my $key ( qw( type_name year month ) ) { 16 16 last unless $vars->{$key}; 17 17 $base_url .= "/$vars->{$key}"; trunk/templates/top.mason
r81 r82 1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 4 "http://www.w3.org/TR/html4/loose.dtd"> 5 1 6 <%args> 2 7 $title
