| 1 | package SWISH::Prog::Class; | ||||||||||||||||||||||||
| 2 | 16 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 3 | 16 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 4 | 16 | ▶ | use base qw( Rose::ObjectX::CAF ); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 5 | 16 | ▶ | use Carp; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 6 | 16 | ▶ | use Data::Dump qw( dump ); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 7 | 16 | ▶ | use SWISH::Prog::Config; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 8 | 16 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | 16 | our $VERSION = '0.75'; | |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||
| 12 | 16 | __PACKAGE__->mk_accessors(qw( debug verbose warnings )); | |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||
| 14 | =pod | ||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||
| 18 | SWISH::Prog::Class - base class for SWISH::Prog classes | ||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||
| 22 | package My::Class; | ||||||||||||||||||||||||
| 23 | use base qw( SWISH::Prog::Class ); | ||||||||||||||||||||||||
| 24 | 1; | ||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||
| 26 | # see METHODS for what you get for free | ||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||
| 30 | SWISH::Prog::Class is a subclass of Rose::ObjectX::CAF. | ||||||||||||||||||||||||
| 31 | It's a base class useful for making simple accessor/mutator methods. | ||||||||||||||||||||||||
| 32 | SWISH::Prog::Class implements some additional methods and features | ||||||||||||||||||||||||
| 33 | useful for SWISH::Prog projects. | ||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||
| 35 | =head1 METHODS | ||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||
| 37 | =head2 new( I<params> ) | ||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||
| 39 | Constructor. Returns a new object. May take a hash or hashref | ||||||||||||||||||||||||
| 40 | as I<params>. | ||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||
| 42 | =head2 init | ||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||
| 44 | Override init() in your subclass to perform object maintenance at | ||||||||||||||||||||||||
| 45 | construction time. Called by new(). | ||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||
| 47 | =head2 debug | ||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||
| 49 | Get/set the debug level. Default is 0. | ||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||
| 51 | =head2 warnings | ||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||
| 53 | Get/set the warnings level. Default is 0. | ||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||
| 55 | =head2 verbose | ||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||
| 57 | Get/set flags affecting the verbosity of the program. | ||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||
| 61 | 50 | ▶ | sub init { | ||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||
| 62 | 50 | my $self = shift; | |||||||||||||||||||||||
| 63 | 50 | $self->SUPER::init(@_); | |||||||||||||||||||||||
| 64 | 49 | ▶ | $self->{debug} ||= $ENV{PERL_DEBUG} || 0; | ||||||||||||||||||||||
|
Condition40%2/5
$self->{"debug"} ||= $ENV{"PERL_DEBUG"} || 0
$ENV{'PERL_DEBUG'} || 0
MC/DC0%0/2
$self->{"debug"} ||= $ENV{"PERL_DEBUG"} || 0
$self->{"debug"}
$ENV{'PERL_DEBUG'}
Truth table33%1/3
A ||= B
A= $self->{"debug"}B= $ENV{'PERL_DEBUG'}
| |||||||||||||||||||||||||
| 65 | 49 | ▶ | $self->{verbose} ||= $ENV{PERL_VERBOSE} || 0; | ||||||||||||||||||||||
|
Condition40%2/5
$self->{"verbose"} ||= $ENV{"PERL_VERBOSE"} || 0
$ENV{'PERL_VERBOSE'} || 0
MC/DC0%0/2
$self->{"verbose"} ||= $ENV{"PERL_VERBOSE"} || 0
$self->{"verbose"}
$ENV{'PERL_VERBOSE'}
Truth table33%1/3
A ||= B
A= $self->{"verbose"}B= $ENV{'PERL_VERBOSE'}
| |||||||||||||||||||||||||
| 66 | 49 | $self->{_start} = time(); | |||||||||||||||||||||||
| 67 | 49 | return $self; | |||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||
| 70 | =head2 elapsed | ||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||
| 72 | Returns the elapsed time in seconds since object was created. | ||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||
| 76 | 0 | ▶ | sub elapsed { | ||||||||||||||||||||||
|
Subroutine
elapsed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||
| 77 | 0 | return time() - shift->{_start}; | |||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||
| 80 | =head2 dump( [I<data>] ) | ||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||
| 82 | Returns $self (and I<data> if present) via Data::Dump::dump. Useful for peering | ||||||||||||||||||||||||
| 83 | inside an object or other scalar. | ||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||
| 85 | =cut | ||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||
| 87 | =head2 verify_isa_swish_prog_config([I<config>]) | ||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||
| 89 | Returns a SWISH::Prog::Config object based on I<config>. | ||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||
| 91 | I<config> may be a readable file name or a SWISH::Prog::Config object. | ||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||
| 93 | Will croak if I<config> is neither of the above. | ||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||
| 95 | =cut | ||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||
| 97 | 0 | ▶ | sub verify_isa_swish_prog_config { | ||||||||||||||||||||||
|
Subroutine
verify_isa_swish_prog_config: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||
| 98 | 0 | my $self = shift; | |||||||||||||||||||||||
| 99 | 0 | my $config2 = shift; | |||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||
| 101 | #carp "verify_isa_config: $config2"; | ||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||
| 103 | 0 | my $config2_object; | |||||||||||||||||||||||
| 104 | 0 | ▶ | if ( !$config2 ) { | ||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||
| 105 | 0 | $config2_object = SWISH::Prog::Config->new(); | |||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||
| 107 | ▶ | elsif ( !blessed($config2) && -r $config2 ) { | |||||||||||||||||||||||
|
Condition0%0/3
not builtin::blessed($config2) and -r $config2
MC/DC0%0/2
not builtin::blessed($config2) and -r $config2
not builtin::blessed($config2)
-r $config2
Truth table0%0/3
not(A) and B
A= not builtin::blessed($config2)B= -r $config2
| |||||||||||||||||||||||||
| 108 | 0 | $config2_object = SWISH::Prog::Config->new($config2); | |||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||
| 110 | ▶ | elsif ( !blessed($config2) && ref $config2 eq 'HASH' ) { | |||||||||||||||||||||||
|
Condition0%0/3
not builtin::blessed($config2) and ref $config2 eq "HASH"
MC/DC0%0/2
not builtin::blessed($config2) and ref $config2 eq "HASH"
not builtin::blessed($config2)
ref $config2 eq "HASH"
Truth table0%0/3
not(A) and B
A= not builtin::blessed($config2)B= ref $config2 eq "HASH"
| |||||||||||||||||||||||||
| 111 | 0 | $config2_object = SWISH::Prog::Config->new($config2); | |||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||
| 113 | elsif ( blessed($config2) ) { | ||||||||||||||||||||||||
| 114 | 0 | ▶ | if ( !$config2->isa('SWISH::Prog::Config') ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 115 | 0 | croak | |||||||||||||||||||||||
| 116 | "config object does not inherit from SWISH::Prog::Config: $config2"; | ||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||
| 118 | else { | ||||||||||||||||||||||||
| 119 | 0 | $config2_object = $config2; | |||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||
| 123 | 0 | croak "$config2 is neither an object nor a readable file"; | |||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||
| 126 | 0 | return $config2_object; | |||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||
| 129 | 16 | 1; | |||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||