File Coverage

blib/lib/Text/Livedoor/Wiki/CatalogKeeper.pm
Criterion Covered Total %
statement 56 56 100.0
branch 19 20 95.0
condition 3 3 100.0
subroutine 6 6 100.0
pod 3 3 100.0
total 87 88 98.8


line stmt bran cond sub pod time code
1             package Text::Livedoor::Wiki::CatalogKeeper;
2              
3 10     10   58 use strict;
  10         97  
  10         351  
4 10     10   52 use warnings;
  10         16  
  10         272  
5 10     10   3447 use Data::Dumper;
  10         29271  
  10         6093  
6              
7             my $NO_SETTING = " ";
8              
9             sub new {
10 92     92 1 156 my $class =shift;
11 92         347 my $self = bless {} ,$class;
12 92         326 $self->{data} = [];
13 92         327 return $self;
14             }
15             sub append {
16 58     58 1 100 my $self = shift;
17 58         92 my $args = shift;
18 58         86 push @{$self->{data}} , $args;
  58         302  
19             }
20              
21             sub contents {
22 76     76 1 136 my $self = shift;
23              
24             # divでこのうえを囲わない
25 76         142 my $prev = 0;
26 76         136 my $contents = qq|
\n
\n
    \n|;
27 76         164 for ( my $i = 0 ; $i < scalar @{ $self->{data} } ; $i++ ) {
  116         438  
28 40         53 my $flg = 1;
29 40         81 my $item = $self->{data}[$i];
30 40 100       54 my $next = scalar @{$self->{data}} != $i+1 ? $self->{data}[$i+1]{level} : 0;
  40         229  
31 40         195 while( $flg ) {
32 46 100       127 if( $item->{level} > $prev + 1 ) {
33 6         11 $prev++;
34             #my $n = $prev == $item->{level} ? $next : $prev+1;
35 6         12 my $n = $next ;
36 6         29 $contents .= sprintf( qq|
  • $NO_SETTING| , $prev );
  • 37              
    38 6 100       34 if( $prev == $n ) {
        100          
        50          
    39 2         8 $contents .= "\n";
    40             }
    41             elsif( $prev > $n ) {
    42 1         3 my $diff= $item->{level} - $n;
    43 1         3 $contents .= "\n";
    44 1         3 for(1..$diff) {
    45 3         6 $contents .= "\n\n";
    46             }
    47             }
    48             elsif( $prev < $n ) {
    49 3         8 $contents .= "\n
      \n";
    50             }
    51              
    52 6         15 next;
    53             }
    54 40 100       107 $prev= 1 if $prev== 0;
    55 40         99 $flg = 0;
    56             }
    57 40         277 $contents .= sprintf( qq|
  • %s| , $item->{level} , $item->{id} , $item->{label} );
  • 58              
    59 40 100 100     254 if( $item->{level} == $next ) {
        100          
        100          
    60 5         8 $contents .= "\n";
    61             }
    62             elsif( $next != 0 && $item->{level} > $next ) {
    63 7         19 my $diff= $item->{level} - $next;
    64 7         10 $contents .= "\n";
    65 7         21 for(1..$diff) {
    66 10         22 $contents .= "\n\n";
    67             }
    68             }
    69             elsif( $item->{level} < $next ) {
    70 14         25 $contents .= "\n
      \n";
    71             }
    72              
    73 40 100       94 if( $next == 0 ) {
    74 14         34 $contents .= "\n";
    75 14         69 for(1..($item->{level}-1)) {
    76 10         23 $contents .= "\n";
    77             }
    78             }
    79              
    80 40         96 $prev = $item->{level};
    81             }
    82              
    83 76         257 $contents .= "\n\n\n";
    84              
    85 76         270 return $contents;
    86             }
    87              
    88             1;
    89              
    90             =head1 NAME
    91              
    92             Text::Livedoor::Wiki::CatalogKeeper - Catalog Keeper
    93              
    94             =head1 DESCRIPTION
    95              
    96             keep h3,h4,h5 catalog
    97              
    98             =head1 METHOD
    99              
    100             =head2 append
    101              
    102             =head2 contents
    103              
    104             =head2 new
    105              
    106             =head1 AUTHOR
    107              
    108             polocky
    109              
    110             =cut