| blib/lib/Text/Livedoor/Wiki/Plugin/Block/H4.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % | 
| statement | 49 | 49 | 100.0 | 
| branch | 8 | 8 | 100.0 | 
| condition | 13 | 15 | 86.6 | 
| subroutine | 5 | 5 | 100.0 | 
| pod | 2 | 2 | 100.0 | 
| total | 77 | 79 | 97.4 | 
| line | stmt | bran | cond | sub | pod | time | code | 
|---|---|---|---|---|---|---|---|
| 1 | package Text::Livedoor::Wiki::Plugin::Block::H4; | ||||||
| 2 | |||||||
| 3 | 5 | 5 | 30 | use warnings; | |||
| 5 | 12 | ||||||
| 5 | 148 | ||||||
| 4 | 5 | 5 | 29 | use strict; | |||
| 5 | 46 | ||||||
| 5 | 175 | ||||||
| 5 | 5 | 5 | 26 | use base qw(Text::Livedoor::Wiki::Plugin::Block); | |||
| 5 | 11 | ||||||
| 5 | 1375 | ||||||
| 6 | |||||||
| 7 | sub check { | ||||||
| 8 | 213 | 213 | 1 | 321 | my $class = shift; | ||
| 9 | 213 | 515 | my $line = shift; | ||||
| 10 | 213 | 270 | my $args = shift; | ||||
| 11 | 213 | 342 | my $id = $args->{id}; | ||||
| 12 | 213 | 342 | my $inline = $args->{inline}; | ||||
| 13 | 213 | 320 | my $on_next = $args->{on_next}; | ||||
| 14 | 213 | 325 | my $scratchpad = $Text::Livedoor::Wiki::scratchpad; | ||||
| 15 | |||||||
| 16 | 213 | 429 | my $catalog_keeper = $Text::Livedoor::Wiki::opts->{catalog_keeper}; | ||||
| 17 | 213 | 288 | my $id_keeper = $Text::Livedoor::Wiki::opts->{id_keeper}; | ||||
| 18 | 213 | 525 | my $skip_catalog = $Text::Livedoor::Wiki::opts->{skip_catalog}; | ||||
| 19 | |||||||
| 20 | 213 | 570 | my $key = 'h4_is_active_' . $id; | ||||
| 21 | |||||||
| 22 | # start rule | ||||||
| 23 | # 1. start with **~ | ||||||
| 24 | # 2. not end yet | ||||||
| 25 | #if ( $line =~ /^\*\*[^\*]./ && !$scratchpad->{$key} && !$class->get_child($id)){ | ||||||
| 26 | 213 | 100 | 100 | 2006 | if ( $line =~ /^\*\*[^\*]+/ && !$scratchpad->{$key} && !$class->get_child($id)){ | ||
| 100 | 66 | ||||||
| 100 | 100 | ||||||
| 100 | |||||||
| 66 | |||||||
| 27 | 17 | 67 | $scratchpad->{$key} = 1 ; | ||||
| 28 | 17 | 70 | $line =~ s/^\*\*//; | ||||
| 29 | 17 | 77 | my $title = $inline->parse($line); | ||||
| 30 | 17 | 46 | my $header = ''; | ||||
| 31 | |||||||
| 32 | #XXX | ||||||
| 33 | 17 | 43 | $Text::Livedoor::Wiki::scratchpad->{skip_ajust_block_break} = '1'; | ||||
| 34 | |||||||
| 35 | 17 | 100 | 49 | if( $skip_catalog ) { | |||
| 36 | 3 | 16 | $header = sprintf( qq| %s | ||||
| 37 | } | ||||||
| 38 | else { | ||||||
| 39 | 14 | 76 | $id_keeper->up(2); | ||||
| 40 | 14 | 61 | $catalog_keeper->append( {level=>2 , id => $id_keeper->id(2) , label => $title } ); | ||||
| 41 | 14 | 57 | $header = sprintf( qq| %s | ||||
| 42 | } | ||||||
| 43 | 17 | 137 | return { header => $header , id => $id }; | ||||
| 44 | } | ||||||
| 45 | # end rule | ||||||
| 46 | # 1. next line | ||||||
| 47 | # 2. no not-closed child block | ||||||
| 48 | # 3. * | ||||||
| 49 | elsif( $on_next && $class->trigger_check($id,$line) && $line =~ /^\*/ && $scratchpad->{$key} ) { | ||||||
| 50 | 14 | 31 | $scratchpad->{$key} = 0 ; | ||||
| 51 | 14 | 102 | return ; | ||||
| 52 | } | ||||||
| 53 | elsif( $scratchpad->{$key} ) { | ||||||
| 54 | 26 | 159 | return { line => $line }; | ||||
| 55 | } | ||||||
| 56 | |||||||
| 57 | 156 | 817 | return; | ||||
| 58 | |||||||
| 59 | } | ||||||
| 60 | |||||||
| 61 | sub get { | ||||||
| 62 | 17 | 17 | 1 | 38 | my $class = shift; | ||
| 63 | 17 | 27 | my $block = shift; | ||||
| 64 | 17 | 31 | my $inline = shift; | ||||
| 65 | 17 | 28 | my $items = shift; | ||||
| 66 | 17 | 31 | my $meta = shift @{$items}; | ||||
| 17 | 39 | ||||||
| 67 | 17 | 51 | my $header = $meta->{header} ; | ||||
| 68 | 17 | 39 | my $id = $meta->{id} ; | ||||
| 69 | 17 | 31 | my $html = ''; | ||||
| 70 | 17 | 74 | $html .= $_->{line} . "\n" for @$items; | ||||
| 71 | 17 | 64 | $html =~ s/\n$//; | ||||
| 72 | # block in block | ||||||
| 73 | 17 | 79 | $html = $block->parse( $html , 1 ) ; | ||||
| 74 | 17 | 149 | return qq| \n$header\n|; \n$html\n | ||||
| 75 | } | ||||||
| 76 | |||||||
| 77 | 1; | ||||||
| 78 | |||||||
| 79 | =head1 NAME | ||||||
| 80 | |||||||
| 81 | Text::Livedoor::Wiki::Plugin::Block::H4 - H4 Block Plugin | ||||||
| 82 | |||||||
| 83 | =head1 DESCRIPTION | ||||||
| 84 | |||||||
| 85 | H4 is second level header | ||||||
| 86 | |||||||
| 87 | =head1 SYNOPSIS | ||||||
| 88 | |||||||
| 89 | ** title2 | ||||||
| 90 | |||||||
| 91 | content | ||||||
| 92 | |||||||
| 93 | ** title2 | ||||||
| 94 | |||||||
| 95 | =head1 FUNCTION | ||||||
| 96 | |||||||
| 97 | =head2 check | ||||||
| 98 | |||||||
| 99 | =head2 get | ||||||
| 100 | |||||||
| 101 | =head1 AUTHOR | ||||||
| 102 | |||||||
| 103 | polocky | ||||||
| 104 | |||||||
| 105 | =cut |