| 1 | ## -*- perl -*- | ||
| 2 | ##---------------------------------------------------------------------------- | ||
| 3 | ## Markdown Parser Only - ~/lib/Markdown/Parser/Checkbox.pm | ||
| 4 | ## Version v0.2.0 | ||
| 5 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||
| 6 | ## Author: Jacques Deguest <jack@deguest.jp> | ||
| 7 | ## Created 2021/08/23 | ||
| 8 | ## Modified 2022/09/19 | ||
| 9 | ## All rights reserved | ||
| 10 | ## | ||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||
| 12 | ## under the same terms as Perl itself. | ||
| 13 | ##---------------------------------------------------------------------------- | ||
| 14 | package Markdown::Parser::Checkbox; | ||
| 15 | BEGIN | ||
| 16 | { | ||
| 17 | use strict; | ||
| 18 | use warnings; | ||
| 19 | use parent qw( Markdown::Parser::Element ); | ||
| 20 | use vars qw( $VERSION ); | ||
| 21 | use Devel::Confess; | ||
| 22 | our $VERSION = 'v0.2.0'; | ||
| 23 | }; | ||
| 24 | |||
| 25 | use strict; | ||
| 26 | use warnings; | ||
| 27 | |||
| 28 | sub init | ||
| 29 | { | ||
| 30 | my $self = shift( @_ ); | ||
| 31 | $self->{tag_name} = 'checkbox'; | ||
| 32 | $self->{checked} = 0; | ||
| 33 | $self->{disabled} = 0; | ||
| 34 | return( $self->SUPER::init( @_ ) ); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub as_markdown | ||
| 38 | { | ||
| 39 | my $self = shift( @_ ); | ||
| 40 | my $checked = $self->checked; | ||
| 41 | return( ' [' . ( $checked ? 'X' : ' ' ) . '] ' ); | ||
| 42 | } | ||
| 43 | |||
| 44 | sub as_pod | ||
| 45 | { | ||
| 46 | my $self = shift( @_ ); | ||
| 47 | my $checked = $self->checked; | ||
| 48 | return( ' [' . ( $checked ? 'X' : ' ' ) . '] ' ); | ||
| 49 | } | ||
| 50 | |||
| 51 | sub as_string | ||
| 52 | { | ||
| 53 | my $self = shift( @_ ); | ||
| 54 | my $arr = $self->new_array( [' <input type="checkbox"'] ); | ||
| 55 | my $checked = $self->checked; | ||
| 56 | my $disabled = $self->disabled; | ||
| 57 | my $attr = $self->new_array; | ||
| 58 | $attr->push( $self->format_id ) if( $self->id->length ); | ||
| 59 | $attr->push( $self->format_class ) if( $self->class->length ); | ||
| 60 | my $attributes = $self->format_attributes; | ||
| 61 | $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length ); | ||
| 62 | $arr->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length ); | ||
| 63 | $arr->push( 'disabled' ) if( $disabled ); | ||
| 64 | $arr->push( 'checked' ) if( $checked ); | ||
| 65 | $arr->push( '/> ' ); | ||
| 66 | return( $arr->join( ' ' )->scalar ); | ||
| 67 | } | ||
| 68 | |||
| 69 | sub checked { return( shift->_set_get_boolean( 'checked', @_ ) ); } | ||
| 70 | |||
| 71 | sub disabled { return( shift->_set_get_boolean( 'disabled', @_ ) ); } | ||
| 72 | |||
| 73 | 1; | ||
| 74 | # NOTE: POD | ||
| 75 | __END__ |