Source

Kephra / lib / ded / Kephra / API.pm

use v5.12;
use warnings;

package Kephra::API;
our $VERSION = 0.2;
use Scalar::Util qw(blessed);

BEGIN {  # because API is called first at start, to even work when mutually recursive included
    require Exporter;
    our @ISA = qw(Exporter);
    our @EXPORT_OK = qw( 
        app_window doc_panel doc_bar editor input output focus focus_back
        message warning error
        output is_widget is_panel is_sizer is_color is_font is_editor is_document
    );
    our %EXPORT_TAGS = (log => [qw(message warning error)], 
                        cmp => [qw(is_widget is_panel is_sizer is_color is_font is_editor is_document)],
                        app => [qw(app_window doc_panel doc_bar editor input output)],
    );
    my %seen;                                                 # code for :all tag
    push @{$EXPORT_TAGS{all}}, grep {!$seen{$_}++} @{$EXPORT_TAGS{$_}} for keys %EXPORT_TAGS;
}

# application parts, environment
#sub app          { }
sub app_window   { $Kephra::App::win           }
sub doc_panel    { app_window()->doc_panel() }
sub doc_bar      { doc_panel()->active_doc_bar()}
sub all_doc_bar   { doc_panel()->all_doc_bar()   }
sub document     { Kephra::DocumentStash::active_doc()   }
sub all_documents{ Kephra::DocumentStash::all_docs()     }
sub editor       { Kephra::DocumentStash::active_editor()}
#sub input        { }
#sub output       { }
#
sub focus        { Kephra::App::Focus::set(@_) }
sub focus_back   { Kephra::App::Focus::set_back(@_) }

# logging
sub message      { Kephra::Log::message(@_) }
sub warning      { Kephra::Log::warning(@_) }
sub error        { Kephra::Log::error(@_)   }

# comparison checker
sub is_widget    {(blessed($_[0]) and $_[0]->isa('Wx::Window')              )  ? 1 : 0}
sub is_editor    {(blessed($_[0]) and $_[0]->isa('Kephra::App::Editor')     )  ? 1 : 0}
sub is_document  {(blessed($_[0]) and $_[0]->isa('Kephra::Document')        )  ? 1 : 0}
sub is_panel     {(blessed($_[0]) and $_[0]->isa('Wx::Panel')               )  ? 1 : 0}
sub is_sizer     {(blessed($_[0]) and $_[0]->isa('Wx::Sizer')               )  ? 1 : 0}
sub is_color     {(blessed($_[0]) and $_[0]->isa('Wx::Colour') and $_[0]->IsOk)? 1 : 0}
sub is_font      {(blessed($_[0]) and $_[0]->isa('Wx::Font') and $_[0]->IsOk)  ? 1 : 0}


'love and light';