diff Lib/IMPL/Profiler/Memory.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents cd1ff7029a63
children
line wrap: on
line diff
--- a/Lib/IMPL/Profiler/Memory.pm	Tue Apr 10 08:13:22 2012 +0400
+++ b/Lib/IMPL/Profiler/Memory.pm	Tue Apr 10 20:08:29 2012 +0400
@@ -8,47 +8,47 @@
 my $trapped;
 
 BEGIN {
-	$trapped = 0;
+    $trapped = 0;
 }
 
 sub import {
-	if (not $trapped) {
-	    *CORE::GLOBAL::bless = sub {
-	        $_[1] |= caller unless $_[1];
-	        my $ref = CORE::bless $_[0],$_[1];
-	
-	        $_->track($ref) foreach values %listeners;
-	
-	        return $ref;
-	    };
-	    $trapped = 1;
-	}
+    if (not $trapped) {
+        *CORE::GLOBAL::bless = sub {
+            $_[1] |= caller unless $_[1];
+            my $ref = CORE::bless $_[0],$_[1];
+    
+            $_->track($ref) foreach values %listeners;
+    
+            return $ref;
+        };
+        $trapped = 1;
+    }
 }
 
 sub _ConnectListener {
-	my ($self,$listener) = @_;
-	
-	die "Invalid listener" unless ref $listener;
-	
-	$listeners{refaddr($listener)} = $listener;
+    my ($self,$listener) = @_;
+    
+    die "Invalid listener" unless ref $listener;
+    
+    $listeners{refaddr($listener)} = $listener;
 }
 
 sub _RemoveListener {
-	my ($self,$listener) = @_;
-	
-	die "Invalid listener" unless ref $listener;
-	
-	delete $listeners{refaddr($listener)};
+    my ($self,$listener) = @_;
+    
+    die "Invalid listener" unless ref $listener;
+    
+    delete $listeners{refaddr($listener)};
 }
 
 sub Monitor {
-	my ($self,$code) = @_;
-	
-	my $data = IMPL::Profiler::Memory::Data->new();
-	
-	$data->Monitor($code);
-	
-	return $data; 
+    my ($self,$code) = @_;
+    
+    my $data = IMPL::Profiler::Memory::Data->new();
+    
+    $data->Monitor($code);
+    
+    return $data; 
 }
 
 package IMPL::Profiler::Memory::Data;
@@ -60,50 +60,50 @@
 use fields qw( objects counter);
 
 sub CTOR {
-	my $this = shift;
-	$this->{objects} = [];
-	$this->{counter} = 0;
+    my $this = shift;
+    $this->{objects} = [];
+    $this->{counter} = 0;
 }
 
 sub track {
-	my $i = scalar @{$_[0]->{objects}};
-	$_[0]->{objects}[$i] = $_[1];
-	weaken($_[0]->{objects}[$i]);
-	$_[0]->{counter} ++;
+    my $i = scalar @{$_[0]->{objects}};
+    $_[0]->{objects}[$i] = $_[1];
+    weaken($_[0]->{objects}[$i]);
+    $_[0]->{counter} ++;
 }
 
 sub Purge {
-	my $this = shift;
-	
-	return $this->{objects} = [ grep defined($_), @{$this->{objects}}];
+    my $this = shift;
+    
+    return $this->{objects} = [ grep defined($_), @{$this->{objects}}];
 }
 
 sub Dump {
-	my $this = shift;
-	return Data::Dumper->Dump([$this->{objects}]);
+    my $this = shift;
+    return Data::Dumper->Dump([$this->{objects}]);
 }
 
 sub isLeak {
-	my ($this) = @_;
-	$this->Purge();
-	return ( scalar(@{$this->{objects}}) > 0);
+    my ($this) = @_;
+    $this->Purge();
+    return ( scalar(@{$this->{objects}}) > 0);
 }
 
 sub Monitor {
-	my ($this,$code) = @_;
-	
-	die "A reference to a subroutine is required" unless ref $code;
-	
-	IMPL::Profiler::Memory->_ConnectListener($this);
-	eval {
-		$code->();
-	};
-	my $err = $@;
-	IMPL::Profiler::Memory->_RemoveListener($this);
-	
-	die $err if $err;
-	
-	return;
+    my ($this,$code) = @_;
+    
+    die "A reference to a subroutine is required" unless ref $code;
+    
+    IMPL::Profiler::Memory->_ConnectListener($this);
+    eval {
+        $code->();
+    };
+    my $err = $@;
+    IMPL::Profiler::Memory->_RemoveListener($this);
+    
+    die $err if $err;
+    
+    return;
 }