<commit_before>#!/usr/bin/ruby -w
###########################################################################

=begin

= debugging.rb

== NAME

Debuggable - a mixin module for debugging methods

== SYNOPSIS

  require "mues/debugging"

  class MyClass < Object
	include Debuggable

	def initialize
	  _debugMsg( "Initializing..." )
	end
  end

== DESCRIPTION

This module is a module of debugging mixins that can be used for debugging. And
stuff.

== AUTHOR

<NAME> <((<<EMAIL>|URL:mailto:<EMAIL>>))>

Copyright (c) 2000 The FaerieMUD Consortium. All rights reserved.

This module is free software. You may use, modify, and/or redistribute this
software under the terms of the Perl Artistic License. (See
http://language.perl.com/misc/Artistic.html)

=end

###########################################################################

module Debuggable

	def Debuggable.append_features( klass )
		klass.class_eval {
			@debugged = false
		}
		super
	end

	def _debugMsg( *messages )
		return nil unless debugged?
		level = messages[0].is_a?( Fixnum ) ? messages.shift : 5
		return unless debugged() >= level

		logMessage = messages.collect {|m| m.to_s}.join('')
		frame = caller(1)[0]
		if Thread.current != Thread.main then
			$stderr.puts "[Thread #{Thread.current.id}] #{frame}: #{logMessage}"
		else
			$stderr.puts "#{frame}: #{logMessage}"
		end
	end

	def debugged
		return false unless debugged?
		@debugged
	end

	def debugged=( value )
		@debugged = value
	end

	def debugged?
		defined?( @debugged ) && @debugged > 0
	end

end<commit_msg>- Modified methodology so including Debuggable is less intrusive. It now adds   singleton attributes to objects instead of depending on a global class   attribute added via a class_eval() in the append_features() hook. This makes   it possible to do per-object debugging as well as per-class debugging.<commit_after>#!/usr/bin/ruby -w
###########################################################################

=begin

= debugging.rb

== NAME

Debuggable - a mixin module for debugging methods

== SYNOPSIS

  require "mues/debugging"

  class MyClass < Object
	include Debuggable

	def initialize
	  _debugMsg( 1, "Initializing..." )
	end
  end

== DESCRIPTION

This module is a module of debugging mixins that can be used for debugging. And
stuff.

== AUTHOR

<NAME> <((<<EMAIL>|URL:mailto:<EMAIL>>))>

Copyright (c) 2000 The FaerieMUD Consortium. All rights reserved.

This module is free software. You may use, modify, and/or redistribute this
software under the terms of the Perl Artistic License. (See
http://language.perl.com/misc/Artistic.html)

=end

###########################################################################

module Debuggable

	def _debugMsg( *messages )
		level = messages[0].is_a?( Fixnum ) ? messages.shift : 5
		return unless debugged?( level )

		logMessage = messages.collect {|m| m.to_s}.join('')
		frame = caller(1)[0]
		if Thread.current != Thread.main then
			$stderr.puts "[Thread #{Thread.current.id}] #{frame}: #{logMessage}"
		else
			$stderr.puts "#{frame}: #{logMessage}"
		end
	end

	def debugLevel
		defined?( @debugLevel ) ? @debugLevel : 0
	end

	def debugLevel=( value )
		case value
		when true
			@debugLevel = 1
		when false
			@debugLevel = 0
		when Fixnum
			level = 5 if level > 5
			level = 0 if level < 0
			@debugLevel = level
		else
			raise TypeError, "Cannot set debugging level to #{value.to_s}"
		end
	end

	def debugged?( level=1 )
		debugLevel() >= level
	end

end
{'fraction_non_alphanumeric': 0.18563218390804598, 'fraction_numerical': 0.007471264367816092, 'mean_word_length': 4.081751824817518, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1739357', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1051, 'n_words': 359}