Changeset 12178
- Timestamp:
- 05/22/08 08:31:22 (6 months ago)
- Location:
- lang/perl/mobirc/trunk
- Files:
-
- 1 added
- 3 modified
-
Makefile.PL (modified) (1 diff)
-
lib/App/Mobirc.pm (modified) (5 diffs)
-
lib/App/Mobirc/Model/Channel.pm (modified) (1 diff)
-
lib/App/Mobirc/Model/Server.pm (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/mobirc/trunk/Makefile.PL
r12153 r12178 6 6 7 7 requires 'Moose' => 0.44; 8 requires 'MooseX::Singleton' => 0.07; 8 9 requires 'CGI'; 9 10 requires 'CGI::Cookie'; -
lang/perl/mobirc/trunk/lib/App/Mobirc.pm
r12148 r12178 1 1 package App::Mobirc; 2 use strict; 3 use warnings; 2 use Moose; 4 3 use 5.00800; 5 4 use Scalar::Util qw/blessed/; … … 10 9 use UNIVERSAL::require; 11 10 use Carp; 12 use App::Mobirc::Model:: Channel;11 use App::Mobirc::Model::Server; 13 12 use Encode; 14 13 … … 21 20 }; 22 21 22 has 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 29 has config => ( 30 is => 'ro', 31 isa => 'HashRef', 32 required => 1, 33 ); 34 23 35 my $context; 24 36 sub context { $context } 25 37 26 sub new{27 my ($ class, $config_stuff) = @_;38 around 'new' => sub { 39 my ($next, $class, $config_stuff) = @_; 28 40 my $config = App::Mobirc::ConfigLoader->load($config_stuff); 29 my $self = bless {config => $config, channels => {}}, $class;30 41 42 my $self = $next->( $class, config => $config ); 31 43 $self->load_plugins; 32 44 … … 34 46 35 47 return $self; 36 } 48 }; 37 49 38 50 sub load_plugins { … … 81 93 croak "hook point missing" unless $hook_point; 82 94 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};111 95 } 112 96 -
lang/perl/mobirc/trunk/lib/App/Mobirc/Model/Channel.pm
r12148 r12178 12 12 sub new { 13 13 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; 15 16 croak "missing channel name" unless defined $name; 16 17 croak "Invalid channel name $name" if $name =~ / /;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)