| 1 | package Book::Bilingual; | ||
| 2 | # ABSTRACT: Data structure for a bilingual book | ||
| 3 | use Mojo::Base -base; | ||
| 4 | use Carp; | ||
| 5 | |||
| 6 | use version; our $VERSION = version->declare('0.002'); | ||
| 7 | |||
| 8 | has 'chapters'; # ArrayRef of Book::Bilingual::Chapter | ||
| 9 | |||
| 10 | sub new { $_[0]->SUPER::new({ chapters => [] }) } | ||
| 11 | sub chapter_count { ## () :> Int | ||
| 12 | my ($self) = @_; | ||
| 13 | |||
| 14 | return scalar @{$self->{chapters}}; | ||
| 15 | } | ||
| 16 | sub push { ## ($chapter:>Book::Bilingual::Chapter) :> Self | ||
| 17 | my ($self, $chapter) = @_; | ||
| 18 | |||
| 19 | croak 'Not a Book::Bilingual::Chapter' | ||
| 20 | unless ref($chapter) eq 'Book::Bilingual::Chapter'; | ||
| 21 | |||
| 22 | push @{$self->{chapters}}, $chapter; | ||
| 23 | |||
| 24 | return $self; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub chapter_at { ## ($ch_idx :>Int) :> Int | ||
| 28 | my ($self, $ch_idx) = @_; | ||
| 29 | return $self->{chapters}[$ch_idx]; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub chapter_dlineset_count { ## ($ch_idx) :> Int | ||
| 33 | my ($self,$ch_idx) = @_; | ||
| 34 | return $self->chapters->[$ch_idx]->dlineset_count; | ||
| 35 | } | ||
| 36 | sub chapter_dlineset_dline_len { ## ($ch_idx, $dset_idx) :> Int | ||
| 37 | my ($self, $ch_idx, $dset_idx) = @_; | ||
| 38 | return $self->chapters->[$ch_idx]->dlineset_at($dset_idx)->dline_count; | ||
| 39 | } | ||
| 40 | |||
| 41 | 1; | ||
| 42 | |||
| 43 | =pod | ||
| 44 | |||
| 45 | =encoding utf-8 | ||
| 46 | |||
| 47 | =head1 NAME | ||
| 48 | |||
| 49 | Book::Bilingual - A crappy model for bilingual books | ||
| 50 | |||
| 51 | =head1 SYNOPSIS | ||
| 52 | |||
| 53 | use Book::Bilingual::Reader; | ||
| 54 | |||
| 55 | my $file = 't/ff01.mdown'; | ||
| 56 | my $reader = Book::Bilingual::Reader->new($file); | ||
| 57 | |||
| 58 | print $reader->html(); | ||
| 59 | |||
| 60 | =head1 DESCRIPTION | ||
| 61 | |||
| 62 | L<Book::Bilingual> is a model for bilingual books written in Markdown | ||
| 63 | format. The L<Book::Bilingual::Reader> module reads the file and | ||
| 64 | generates HTML. | ||
| 65 | |||
| 66 | =head1 METHODS | ||
| 67 | |||
| 68 | =head2 chapter_dlineset_count($chapter_idx:>Int) :> Int | ||
| 69 | |||
| 70 | Returns the number of dlinesets in the given Chapter. | ||
| 71 | |||
| 72 | =head2 num_dline_in_dlineset($chapter_idx:Int, $dlineset_idx:Int) :> Int | ||
| 73 | |||
| 74 | Returns the number of dlines in the given Chapter and Dlineset. | ||
| 75 | |||
| 76 | =head1 AUTHOR | ||
| 77 | |||
| 78 | Hoe Kit CHEW E<lt>hoekit at gmail.comE<gt> | ||
| 79 | |||
| 80 | =head1 COPYRIGHT | ||
| 81 | |||
| 82 | Copyright (C) 2021 Hoe Kit CHEW | ||
| 83 | |||
| 84 | =head1 LICENSE | ||
| 85 | |||
| 86 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||
| 87 | |||
| 88 | =cut | ||
| 89 |