Changeset 12178

Show
Ignore:
Timestamp:
05/22/08 08:31:22 (6 months ago)
Author:
tokuhirom
Message:

more moose

Location:
lang/perl/mobirc/trunk
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/mobirc/trunk/Makefile.PL

    r12153 r12178  
    66 
    77requires 'Moose' => 0.44; 
     8requires 'MooseX::Singleton' => 0.07; 
    89requires 'CGI'; 
    910requires 'CGI::Cookie'; 
  • lang/perl/mobirc/trunk/lib/App/Mobirc.pm

    r12148 r12178  
    11package App::Mobirc; 
    2 use strict; 
    3 use warnings; 
     2use Moose; 
    43use 5.00800; 
    54use Scalar::Util qw/blessed/; 
     
    109use UNIVERSAL::require; 
    1110use Carp; 
    12 use App::Mobirc::Model::Channel; 
     11use App::Mobirc::Model::Server; 
    1312use Encode; 
    1413 
     
    2120}; 
    2221 
     22has server => ( 
     23    is      => 'ro', 
     24    isa     => 'App::Mobirc::Model::Server', 
     25    default => sub { App::Mobirc::Model::Server->instance() }, 
     26    handles => [qw/add_channel delete_channel channels get_channel delete_channel/], # for backward compatibility 
     27); 
     28 
     29has config => ( 
     30    is       => 'ro', 
     31    isa      => 'HashRef', 
     32    required => 1, 
     33); 
     34 
    2335my $context; 
    2436sub context { $context } 
    2537 
    26 sub new { 
    27     my ($class, $config_stuff) = @_; 
     38around 'new' => sub { 
     39    my ($next, $class, $config_stuff) = @_; 
    2840    my $config = App::Mobirc::ConfigLoader->load($config_stuff); 
    29     my $self = bless {config => $config, channels => {}}, $class; 
    3041 
     42    my $self = $next->( $class, config => $config ); 
    3143    $self->load_plugins; 
    3244 
     
    3446 
    3547    return $self; 
    36 } 
     48}; 
    3749 
    3850sub load_plugins { 
     
    8193    croak "hook point missing" unless $hook_point; 
    8294    return $self->{hooks}->{$hook_point} || []; 
    83 } 
    84  
    85 # ------------------------------------------------------------------------- 
    86  
    87 sub add_channel { 
    88     my ($self, $channel) = @_; 
    89     croak "missing channel" unless $channel; 
    90  
    91     $self->{channels}->{$channel->name} = $channel; 
    92 } 
    93  
    94 sub channels { 
    95     my $self = shift; 
    96     my @channels = values %{ $self->{channels} }; 
    97     return wantarray ? @channels : \@channels; 
    98 } 
    99  
    100 sub get_channel { 
    101     my ($self, $name) = @_; 
    102     croak "channel name is flagged utf8" unless Encode::is_utf8($name); 
    103     croak "invalid channel name : $name" if $name =~ / /; 
    104     return $self->{channels}->{$name} ||= App::Mobirc::Model::Channel->new($self, $name); 
    105 } 
    106  
    107 sub delete_channel { 
    108     my ($self, $name) = @_; 
    109     croak "channel name is flagged utf8" unless Encode::is_utf8($name); 
    110     delete $self->{channels}->{$name}; 
    11195} 
    11296 
  • lang/perl/mobirc/trunk/lib/App/Mobirc/Model/Channel.pm

    r12148 r12178  
    1212sub new { 
    1313    my ($class, $global_context, $name) = @_; 
    14     croak "global context missing" unless blessed $global_context && $global_context->isa("App::Mobirc"); 
     14    $global_context = App::Mobirc->context; # XXX this is temporary thing 
     15    croak "global context missing" unless blessed $global_context; 
    1516    croak "missing channel name" unless defined $name; 
    1617    croak "Invalid channel name $name" if $name =~ / /;