Class-Easy

 view release on metacpan or  search on metacpan

lib/Class/Easy.pm  view on Meta::CPAN

		runtime  => {}
	};
	
	foreach my $sub (@sub_list) {
		my ($real_package, $real_sub) = (get_coderef_info (*{"$module\::$sub"}{CODE}));

		if ($real_package eq $module) {
			$sub_by_type->{method}->{$sub} = 1;
		} elsif ($real_sub eq '__ANON__') {
			$sub_by_type->{runtime}->{$sub} = 1;
		} else {
			$sub_by_type->{imported}->{$real_package}->{$real_sub} = $sub; # who needs $real_sub ?
		}
	}
	
	wantarray
		? (keys %{$sub_by_type->{method}}, keys %{$sub_by_type->{runtime}})
		: $sub_by_type;
}

sub list_all_subs_for {
	my $module = shift || (caller)[0];
	my $filter = shift || '';
	
	$module = ref $module
		if ref $module;
	
	my $namespace = \%{$module . '::'};
	
	my $linear_isa;
	
	if ($] < 5.009_005) {
		require Class::Easy::MRO;
		$linear_isa = __get_linear_isa ($module);
	} else {
		require mro;
		$linear_isa = mro::get_linear_isa ($module);
	}
	
	my $sub_by_type = list_local_subs_for ($module);
	$sub_by_type->{inherited}->{$_} = [list_local_subs_for ($_)]
		foreach grep {$_ ne $module} @$linear_isa;
	
	wantarray
		? (
			keys %{$sub_by_type->{method}}, 
			keys %{$sub_by_type->{runtime}},
			map {@{$sub_by_type->{inherited}->{$_}}} keys %{$sub_by_type->{inherited}})
		: $sub_by_type;
}

1;

=head1 NAME

Class::Easy - make class routine easy

=head1 ABSTRACT

This module is a functionality compilation of some good modules from CPAN.
Ideas are taken from Class::Data::Inheritable, Class::Accessor, Modern::Perl
and Moose at least.

Instead of building monstrous alternatives to Moose or making thousand modules
for every function I need, I decide to write small and efficient libraries for
everyday use. Class::Easy::Base is a base component for classes.

=head1 SYNOPSIS

SYNOPSIS

	# automatic loading of strict, warnings and utf8, like common::sense
	use Class::Easy::Import;
	# or same as above + functions like 'has', 'try_to_use', 'timer' and 'logger'
	use Class::Easy;
	
	# try to load package IO::Easy, return 1 when success
	try_to_use ('IO::Easy');
	
	# try to load package IO::Easy, but search for package existence
	# within %INC instead of symbolic table
	try_to_use_inc ('IO::Easy');
	
	# for current package
	has "property_ro"; # make readonly object accessor
	has "property_rw", is => 'rw'; # make readwrite object accessor
	
	has global25 => 25; # make readonly static accessor with value 25
	has "global", global => 1, is => 'rw'; # make readwrite static accessor

	# make subroutine in package main
	make_accessor ('main', 'initialize', default => sub {
		$::initialized = 1;
		return "initialized!";
	});
	
	# see documentation for Class::Easy::Log
	
	# string "[PID] [PACKAGE(STRING)] [DBG] something" logged
	debug "something";

	# see documentation for Class::Easy::Timer

	my $t = timer ('long operation');
	# … long operation

	my $time = $t->lap ('another long op');
	# …

	$time = $t->end;
	# $time contains time between last 'lap' or 'timer'
	# and 'end' call

	$time = $t->total;
	# now $time contains total time between timer init
	# and end call

=head1 FUNCTIONS

=head2 has ($name [, is => 'ro' | 'rw'] [, default => $default], [, global => 1])

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.439 second using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )